对象的键值对

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"]

你可能感兴趣的:(javascript)