对象的键值对

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cherry_zhang18/article/details/82227603

var obj={"one":"I am 1","two":"I am 2"};

var arr = Object.getOwnPropertyNames(obj); //arr=["one", "two"]

var arr2 = Object.keys(obj);//arr=["one", "two"]

var valArr = arr.map(function(i){return obj[i]});//["I am 1", "I am 2"]

var valArr2 = arr2.map(function(i){return obj[i]});//["I am 1", "I am 2"]

//或者2,4和3,5各自合并成一条语句

var valArr22 = Object.keys(obj).map(function(i){return obj[i]});//["I am 1", "I am 2"]

猜你喜欢

转载自blog.csdn.net/cherry_zhang18/article/details/82227603
0条评论
添加一条新回复