-4
let person = {}

let keys = ['name', 'age', 'work'];
let values = ['Adam', 23, 'none'];

// how to make result
 person = {
 'name': 'Adam',
 'age': 23
 'work': 'none'
}
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • What have you tried, and what exactly is the problem with it? Any research, even - have you read e.g. https://stackoverflow.com/q/39127989/3001761? – jonrsharpe Apr 12 '22 at 21:34
  • i have array of keys and array of values and i want create an object with them – Adam Benson Apr 12 '22 at 21:35
  • Yes, I understand the desired outcome, but this isn't a code-writing or tutorial service. Please take the [tour] and read [ask]. – jonrsharpe Apr 12 '22 at 21:36

1 Answers1

-2

A simple loop does just fine.

let person = {}

let keys = ['name', 'age', 'work']; let values = ['Adam', 23, 'none'];

for (const i of Array(keys.length).keys()) {
  const key = keys[i];
  const val = values[i];
  person[key] = val;
}

console.log(person);
async await
  • 1,967
  • 1
  • 8
  • 19