Linked Questions
36 questions linked to/from How to join / combine two arrays to concatenate into one array?
-3 votes
1 answer
44 views
complex JavaScript object [duplicate]
I have 3 Javascript arrays: array1 = ["data", "data1", "data2"] array2 = ["data", "data1", "data2"] array3 = ["data", "data1", "data2"] How can I combine them all, so that I can simply run a single ...
2031 votes
93 answers
2.2m views
How to merge two arrays in JavaScript and de-duplicate items
I have two JavaScript arrays: var array1 = ["Vijendra","Singh"]; var array2 = ["Singh", "Shakya"]; I want the output to be: var array3 = ["Vijendra","Singh","Shakya"]; The output array should have ...
162 votes
8 answers
105k views
spread operator vs array.concat()
What is the difference between spread operator and array.concat() let parts = ['four', 'five']; let numbers = ['one', 'two', 'three']; console.log([...numbers, ...parts]); Array.concat() ...
131 votes
8 answers
133k views
Why does array.concat(…) not modify the array?
So I've created this jqueryui widget. Its creates a div that I can stream errors into. The widget code looks like this: $.widget('ui.miniErrorLog', { logStart: "<ul>", // these next 4 ...
68 votes
2 answers
288k views
Fast way to concatenate strings in nodeJS/JavaScript [duplicate]
I understand that doing something like var a = "hello"; a += " world"; It is relatively very slow, as the browser does that in O(n) . Is there a faster way of doing so without installing new ...
31 votes
5 answers
9k views
Why is using a generator function slower than filling and iterating an array in this example?
A Tale of Two Functions I have one function that fills an array up to a specified value: function getNumberArray(maxValue) { const a = []; for (let i = 0; i < maxValue; i++) { a....
14 votes
2 answers
16k views
"concat" does not join JavaScript arrays together? [duplicate]
I'm running the following code on Webkit: var scriptElements = document.scripts; var scriptUrls = []; // URL matching var regexp = /\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[....
4 votes
3 answers
13k views
Add elements of an array to another array [duplicate]
There are two arrays, for example: arr1 = ["a", "b"]; arr2 = ["c", "d"]; I want to add the elements of the second one to the first one, after this operation arr1 should look like ["a", "b", "c", "d"]....
3 votes
6 answers
2k views
Combining arrays from dictionary in Javascript
I have the following structure: ley objects = { key1: [1, 2, 3], key2: [3,4,6], key3: [5, 6, 7], } How can I combine those arrays keeping any duplicates so I will have [1, 2, 3, 3, 4, 6, 6, ...
-1 votes
1 answer
12k views
How can i concatenate 2 strings in node.js?
var link = 'https://thisIsAlink' var line = 'this is a line' what i have done is var full_path = session.send(link + line) The output i got :https://thisIsAlink this is a line The output i want :...
1 vote
4 answers
471 views
Put two different associative arrays inside one associative array as an array with two associative arrays in javascript
I Want to join two arrays into one array containing two different arrays First Array. I do not mean a simple array but this time around a more complex array with field having the same values on both ...
1 vote
5 answers
333 views
How to push all objects of array2 to array1
I want to push just the objects of array2 into array1. array1 = [{name:'first'}, {name:'second'}]; array2 = [{name:'third'}, {name:'fourth'}, {name:'five'}]; // Desired result array1 = [{name:'first'...
1 vote
2 answers
611 views
JavaScript equivalent of List Operations in Python
Is there a JavaScript Version of the Python expression in the form of nums = [0,0] + [1] * (n) ? n is the number of times an item is repeated. Examples: If n is 3, nums produces [0,0,1,1,1], If n is ...
1 vote
1 answer
736 views
How to pass array of long to ASP.NET Core Controller POST method via AngularJS http.post
I merge two arrays in my AngularJS controller and sent it via http.post: var selectedIds = angular.extend({}, $scope.selectedFirstKeys, $scope.selectedSecondKeys); $http.post("/api/tests/...
1 vote
2 answers
321 views
D3 js update plot just adds new points in the background rather than on top
I am trying to add data on my existing scatter plot but I would like to have the added data points to be in the background or back rather than being on top. When I am appending the new data into the ...