Reputation:
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' ]
Upvotes: 1
Views: 28
Reputation: 5
Try to make with for as a solution
for(let i=0; i<key.length; i++){
key.push(key);
}
Upvotes: 0
Reputation: 28414
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);
Upvotes: 1