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
我们可能会碰到一些这种场景,就是根据对象的键值对来处理逻辑的需求
通常,我会用 Object.keys 或者 Object.values 但是这两个方法只能迭代出 键的数组 或值的数组
Object.keys
Object.values
Object.entries 有个优点就是可以迭代出 键值对数组
const oj = { name:'jslin', age:'16', sex:'男', bag:'xxx', 0:'xxxx' } Object.entries(oj)
实践中,我们可以用 这个键值对数组更快捷高效的去完成特殊场景需求 如:
Object.entries(oj).map(([key,val])=>{ console.log('key:',key,'val:',val) }) Object.entries(oj).forEach(([key,val])=>{ console.log('key:',key,'val:',val) }) for(const [key,val] of Object.entries(oj)){ console.log('key:',key,'val:',val) }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
我们可能会碰到一些这种场景,就是根据对象的键值对来处理逻辑的需求
通常,我会用
Object.keys
或者Object.values
但是这两个方法只能迭代出 键的数组 或值的数组Object.entries 有个优点就是可以迭代出 键值对数组
实践中,我们可以用 这个键值对数组更快捷高效的去完成特殊场景需求
如:
The text was updated successfully, but these errors were encountered: