Currently, my goal is to extract an array of objects from another array. Let's say I have an array consisting of strings:
const strArr = ["Some", "Thing"];
The task at hand is to create a new Array containing 2 objects for each string in the original strArr. This means that the output should look like this:
result:
[{first_key: "Some"}, {second_key: "Some"}, {first_key: "Thing"}, {second_key: "Thing"}]
I have already achieved this using the following code snippet, however, I am aiming to do it without relying on let
:
const numeros = ["some", 'thing']
let arr = [];
numeros.map(valor => {
const titleContains = {
title_contains: valor,
}
const bodyContains = {
body_contains: valor,
}
arr.push(titleContains);
arr.push(bodyContains);
});
console.log(arr)
Although the code above delivers the correct result, the usage of map may not be entirely accurate and I find myself resorting to the use of let
, which is something I would prefer to avoid.