1

input
var key=[ 'id', 'name', 'health', 'status', 'environment', 'serviceType' ]

I am expecting the below output(duplication of the values)

[ 'id', 'name', 'health', 'status', 'environment', 'serviceType', 'id', 'name', 'health', 'status', 'environment', 'serviceType' ]

0

2 Answers 2

1

Using the spread-operator:

const key = [ 'id', 'name', 'health', 'status', 'environment', 'serviceType' ]

const res = [...key, ...key];

console.log(res);

Using Array#concat:

const key = [ 'id', 'name', 'health', 'status', 'environment', 'serviceType' ]

const res = key.concat(key);

console.log(res);

Sign up to request clarification or add additional context in comments.

Comments

0

Try to make with for as a solution

for(let i=0; i<key.length; i++){
   key.push(key);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.