how to assign key value pairs to object js code example

Example 1: add new key value pair to object javascript

const person = {
	name: "Elon Musk"
}

person.age = 49;

console.log(person);
// {name: "Elon Musk", age: 49}

Example 2: javascript create object from key value pairs

let items = 'key1:value1;key2:value2;key3:value3';
let items_array = items.split(';');
let final_items = items_array.map(item => item.split(':'));
// [ [ key1, value1 ], [ key2, value2 ], [ key3, value3 ] ]

let final_result = Object.fromEntries(final_items);
// { "key1" : "value1", "key2" : "value2", "key3" : "value3" }