Could someone please provide guidance on properly assigning values to object properties in this specific situation:
I am extracting the value from a text area, splitting it at each new line. My goal is to assign these split values to a property of an object within an array. The code snippet is as follows:
var items = [{}];
function process() {
var i = 0;
items.forEach((j) => {
j.self = document.getElementById('input').value.split('\n');
});
The function process() is triggered when a button is clicked.
When checking the console, I am seeing the following output:
https://i.sstatic.net/qLUtb.png
Instead of having multiple self values assigned to key[0] as an array, I want only one value to be stored for each key. Each split should be assigned to corresponding keys like key1.self, and so on.
The expected output would resemble something like this (though not entirely accurate):
items[0]{self: split-string[0]},
items[1]{self: split-string[1]},
items[2]{self: split-string[2]},
And so forth...
As opposed to what is currently displayed in the console:
items[0].self[0] = split-string[0];
items[0].self[1] = split-string[1];
items[0].self[2] = split-string[2];
If you understand the issue and have any suggestions, your assistance would be greatly appreciated.