Skip to content

定义

一种以键-值对形式存储数据的数据结构。如:名字-电话号码,通过名字就能找到对应的电话号码,名字就是键(key),电话号就是值(value)。

字典中的键,是值在字典中的索引。

javascript
class Dictionary {
  constructor() {
    this.items = {}
  }

  // 添加一个存储键值对
  set(key, value) {
    this.items[key] = value
  }

  // 根据key返回一个item
  get(key) {
    return this.items.hasOwnProperty(key) ? this.items[key] : undefined
  }

  // 删除一个存储键值对
  remove(key) {
    if (this.items.hasOwnProperty(key)) {
      delete this.items[key]
    }
  }

  // 返回字典中 key
  get keys() {
    return Object.keys(this.items)
  }

  // 返回字典中 value
  get values() {
    return Object.keys(this.items).reduce((r, c, i) => {
      r.push(this.items[c])
      return r
    }, [])
  }
}
const dictionary = new Dictionary()
dictionary.set('zhangsan', 'zhangsan@email.com')
dictionary.set('lisi', 'lisi@email.com')
dictionary.set('zhaowu', 'zhaowu@email.com')

console.log(dictionary)
console.log(dictionary.keys)
console.log(dictionary.values)
console.log(dictionary.items)

console.log('------------------------')
dictionary.remove('zhaowu')
console.log(dictionary.get('zhaowu'))

Layout Switch

Adjust the layout style of VitePress to adapt to different reading needs and screens.

Expand all
The sidebar and content area occupy the entire width of the screen.
Expand sidebar with adjustable values
Expand sidebar width and add a new slider for user to choose and customize their desired width of the maximum width of sidebar can go, but the content area width will remain the same.
Expand all with adjustable values
Expand sidebar width and add a new slider for user to choose and customize their desired width of the maximum width of sidebar can go, but the content area width will remain the same.
Original width
The original layout width of VitePress

Page Layout Max Width

Adjust the exact value of the page width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the page layout
A ranged slider for user to choose and customize their desired width of the maximum width of the page layout can go.

Content Layout Max Width

Adjust the exact value of the document content width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the content layout
A ranged slider for user to choose and customize their desired width of the maximum width of the content layout can go.

Spotlight

Highlight the line where the mouse is currently hovering in the content to optimize for users who may have reading and focusing difficulties.

ONOn
Turn on Spotlight.
OFFOff
Turn off Spotlight.