本文共 844 字,大约阅读时间需要 2 分钟。
判断对象的keys值个数
Object.keys()
accepts an object as argument and returns an array of all its (own) enumerable properties.
Object.keys()
接受一个对象作为参数,并返回其所有(自己的)可枚举属性的数组。
const car = { color: 'Blue', brand: 'Ford', model: 'Fiesta'}Object.keys(car) //[ 'color', 'brand', 'model' ]
I said enumerable properties. This means their internal enumerable flag is set to true, which is the default. for more info on this subject.
我说了无数的属性。 这意味着它们的内部可枚举标志设置为true,这是默认设置。 以获取有关此主题的更多信息。
One use of the Object.keys
function is to create a copy of an object that has all the properties of it, except one:
Object.keys
函数的一种用法是创建一个具有其所有属性的对象的副本,但以下一项除外:
const car = { color: 'blue', brand: 'Ford'}const prop = 'color'const newCar = Object.keys(car).reduce((object, key) => { if (key !== prop) { object[key] = car[key] } return object}, {})
翻译自:
判断对象的keys值个数
转载地址:http://yaqgb.baihongyu.com/