xgqfrms react
e.preventDefault();
e.stopPropagation();
e.nativeEvent.stopImmediatePropagation();
xgqfrms react
e.preventDefault();
e.stopPropagation();
e.nativeEvent.stopImmediatePropagation();
Object.keys()
& Array.some()
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
Object.keys()
方法会返回一个由一个给定对象
的自身可枚举属性组成的数组
,
数组中属性名的排列顺序和使用for...in
循环遍历该对象时返回的顺序一致
(两者的主要区别是 一个for-in
循环还会枚举其原型链
上的属性)。
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/some
some()
方法测试数组中的某些元素是否通过由提供的函数实现的测试。
/**
*
* @param {function} fieldsError
* @returns boolean
*
* @demo: hasErrors(getFieldsError())
*
*/
function hasErrors(fieldsError) {
return(
Object
.keys(fieldsError)
.some(
(field) => (fieldsError[field])
)
);
}
/* Array 对象 */
let arr = ["a", "b", "c"];
console.log(Object.keys(arr));
// "0,1,2"
/* 类数组 对象 */
let obj = { 0 : "a", 1 : "b", 2 : "c"};
console.log(Object.keys(obj));
// "0,1,2"
// 类数组 对象, 随机 key 排序
let anObj = { 100: 'a', 2: 'b', 7: 'c' };
console.log(Object.keys(anObj));
// ['2', '7', '100']
/* Object 对象 */
let abc = {a: "a", b: "b", c: "c"};
console.log(Object.keys(abc));
// (3) ["a", "b", "c"]
let xyz = {x: "xxx", y: "yyy", z: "zzz"};
console.log(Object.keys(xyz));
// (3) ["x", "y", "z"]
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
Object.keys(obj) / Object.keys(arr)
let abc = {a: "a", b: "b", c: "c"};
console.log(Object.keys(abc));
// (3) ["a", "b", "c"]
let xyz = {x: "xxx", y: "yyy", z: "zzz"};
console.log(Object.keys(xyz));
// (3) ["x", "y", "z"]
// array like object with random key ordering
let anObj = { 100: 'a', 2: 'b', 7: 'c' };
console.log(Object.keys(anObj));
// ['2', '7', '100']
// 类数组 对象, 随机 key 排序
let anObj = { 100: 'a', 2: 'b', 7: 'c' };
console.log(Object.keys(anObj));
// ['2', '7', '100']
/* getFoo 是个不可枚举的属性 */
let my_obj = Object.create(
{},
{
getFoo: {
value: function() {return this.foo;}
}
}
);
my_obj.foo = 1;
console.log(Object.keys(my_obj));
// ["foo"]
console.log(my_obj);
// {foo: 1, getFoo: ƒ}
ant-design/ant-design#6834 (comment)