I have an array:
arr = ["a", "b", c"]
I want to double the values e.g.
arr = ["a", "b", c", "a", "b", "c"]
(not in a specific order).
What is the best way to do this in JavaScript?
Possible solution using Array#concat.
Array#concat
var arr = ["a", "b", "c"], res = arr.concat(arr); console.log(res);
You can also use ES6 distribution syntax with Array.push:
Array.push
let arr = ['a', 'b', 'c']; arr.push(...arr); console.log(arr);
Array() , , fill() .
Array()
fill()
var arr = ["a", "b", "c"]; var newArr = [].concat(...Array(3).fill(arr)) console.log(newArr)
for-loop, .
var arr=["a","b","c"]; var len=arr.length; for(var i=len;i<2*len;i++) arr[i]=arr[i-len] console.log(arr);
Source: https://habr.com/ru/post/1675461/More articles:How to prevent the start of the embedded netty server using spring-boot-starter-webflux? - javaVue.js filters in v-for - javascriptPyQt QThread: destroyed while thread is still running - pythonSimulate input in a UWP application - c #Is there a way to save a java variable / object in the application context without xml or properties file - javaConnected connection for bitcoin pool - javahttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1675463/css-100vh-is-too-tall-on-mobile-due-to-browser-ui&usg=ALkJrhi0yxgcdHdhF7A_Vt5r_70-OzDa_AHow to create a Laravel 5.4 session in a database - restHow to deserialize legacy Kotlin data classes using Gson - jsonp-значения в pvclust и результаты hclust - rAll Articles