Storing all the array values into single variable and then using that value as css property through javascript

Viewed 87

Suppose i have this array,

let array = [];

for (let i = 1; i < 101; i++) {
  const element = `${i}px ${i}px #0e96ff`;
  array.push(element);
}

now is it possible to store all the 100 values into single variable and then use that value as a css property like this:

let variable = array;

//css property
let style = { filter:`drop-shadow${vairable}`}

if no then how can i achieve the same result?

thanks in advance.

1 Answers

To do what you want with drop-shadow specifically:

let array = [];

for (let i = 1; i < 101; i++) {
  const element = `drop-shadow(${i}px ${i}px #0e96ff)`;
  array.push(element);
}

//css property
let style = { filter: array.join(' ')};
Related