We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
在Set和Map中,NaN被用作键时,视为是相等的。 普通的Object对象“键值对”中,键名只能是字符串,而Map可以是“值对值”。
Map构造函数可以接受数组,Set或Map实例为参数
// 1 数组必须是二维的,表示键值对的关系 var a = new Map([[1, 2], [3, 4]]) // Map(2) {1 => 2, 3 => 4} // 2 Set var b = new Map(new Set([[1, 2], [3, 4]])) // Map(2) {1 => 2, 3 => 4} // 3 Map var c = new Map(b) // Map(2) {1 => 2, 3 => 4}
Map的属性和方法:
同Set的add
Map 结构原生提供三个遍历器生成函数和一个遍历方法。
const map = new Map([ ['F', 'no'], ['T', 'yes'], ]); for (let key of map.keys()) { console.log(key); } // "F" // "T" for (let value of map.values()) { console.log(value); } // "no" // "yes" for (let item of map.entries()) { console.log(item[0], item[1]); } // "F" "no" // "T" "yes" // 或者 for (let [key, value] of map.entries()) { console.log(key, value); } // "F" "no" // "T" "yes" // 等同于使用map.entries() for (let [key, value] of map) { console.log(key, value); } // "F" "no" // "T" "yes"
表示 Map 结构的默认遍历器接口(Symbol.iterator属性),就是entries方法。
map[Symbol.iterator] === map.entries // true
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Map构造函数可以接受数组,Set或Map实例为参数
Map的属性和方法:
set方法设置键名key对应的键值为value,然后返回整个 Map 结构。如果key已经有值,则键值会被更新,否则就新生成该键。
set方法返回的是当前的Map对象,因此可以采用链式写法。
Map 结构原生提供三个遍历器生成函数和一个遍历方法。
Map 的作用
The text was updated successfully, but these errors were encountered: