我们需要编写一个JavaScript函数,该函数接受一个映射文字值的对象。该函数应创建一个数组数组,每个子数组应恰好包含两个元素。
第一个应该是对应对象对的键,第二个应该是值。
const obj = {
name: 'Nick',
achievements: 158,
points: 14730
};
const retrieveProperties = (obj = {}) => {
const res = [];
for(key in obj){
res.push([ key, obj[key] ]);
};
return res;
};
console.log(retrieveProperties(obj));输出结果
控制台中的输出将是-
[ [ 'name', 'Nick' ], [ 'achievements', 158 ], [ 'points', 14730 ] ]