我有与object
相关联的数组列表。要求是制作一个具有所有关键值的新密钥。
var obj = {
all:[
obj.one,
obj.two
],
one:[
'a',
'b',
'c'
],
two:[
'd',
'e',
'f',
'g'
]
}
//通缉结果
var obj = {
all:[
'a',
'b',
'c'
'd',
'e',
'f',
'g'
],
one:[
'a',
'b',
'c'
],
two:[
'd',
'e',
'f',
'g'
]
}
答案 0 :(得分:1)
import java.util.Scanner;
public class PrintDigits {
public static void main(String [] args) {
Scanner scnr= new Scanner(System.in);
int userInput = 0;
int positiveInt = 0;
System.out.println("enter a positive integer:");
userInput = scnr.nextInt();
positiveInt = userInput % 10;
System.out.println(positiveInt);
scnr.close();
return;
}
}
示例:强>
function accumulateKeyValues(obj){
var accumulated = [];
for(var key in obj)
accumulated = accumulated.concat(obj[key]);
obj["all"] = accumulated;
}
答案 1 :(得分:1)
您可以获取对象的所有键并获取新数组的所有值。
var obj = { one:['a', 'b', 'c'], two: ['d', 'e', 'f', 'g'] };
obj.all = Object.keys(obj).reduce(function (r, k) {
return r.concat(obj[k]);
}, []);
console.log(obj);
.as-console-wrapper { max-height: 100% !important; top: 0; }