If I have:
let a = [1,3,4,5];
how do I dynamically set b
to have the same length as a
with each entry containing "<", i.e.
Expected result:
b = ["<","<","<","<"];
If I have:
let a = [1,3,4,5];
how do I dynamically set b
to have the same length as a
with each entry containing "<", i.e.
Expected result:
b = ["<","<","<","<"];
You can use Array#map:
const a = [1,3,4,5];
const b = a.map(() => "<");
console.log(b);
You can use Array#from:
const a = [1,3,4,5];
const b = Array.from(a, () => "<");
console.log(b);
Or you can use Array#fill:
const a = [1,3,4,5];
const b = new Array(a.length).fill("<");
console.log(b);