showing results for - "how to add two attay into object in javascript"
Stefania
18 Mar 2019
1var keys = ['foo', 'bar', 'baz'];
2var values = [11, 22, 33]
3
4var result =  Object.assign.apply({}, keys.map( (v, i) => ( {[v]: values[i]} ) ) );
5console.log(result); //returns {"foo": 11, "bar": 22, "baz": 33}
Ylann
25 Mar 2020
1var keys = ['foo', 'bar', 'baz'];
2var values = [11, 22, 33]
3
4var result = {};
5keys.forEach((key, i) => result[key] = values[i]);
6console.log(result);