Tag Archives: arrays
• ### How can I create a two dimensional array in JavaScript?

I have been reading online and some places say it isn't possible, some say it is and then give an example and others refute the example, etc. How do I…
• ### Remove duplicates from an array of objects in JavaScript

I have an object that contains an array of objects. things = new Object(); things.thing = new Array(); things.thing.push({place:"here",name:"stuff"}); things.thing.push({place:"there",name:"morestuff"}); things.thing.push({place:"there",name:"morestuff"}); I'm wondering what is the best method to remove…
• ### Get all non-unique values (i.e.: duplicate/more than one occurrence) in an array

I need to check a JavaScript array to see if there are any duplicate values. What's the easiest way to do this? I just need to find what the duplicated…
• ### How to sort an array of integers correctly

Trying to get the highest and lowest value from an array that I know will contain only integers seems to be harder than I thought. var numArray = [140000, 104,…
• ### How to get the difference between two arrays in Javascript?

Is there a way to return the difference between two arrays in JavaScript? For example: var a1 = ['a', 'b']; var a2 = ['a', 'b', 'c', 'd']; // need ["c",…
• ### Most efficient method to groupby on a array of objects

What is the most efficient way to groupby objects in an array? For example, given this array of objects: [ { Phase: "Phase 1", Step: "Step 1", Task: "Task 1",…
• ### Split array into chunks

Let's say that I have an Javascript array looking as following: ["Element 1","Element 2","Element 3",...]; // with close to a hundred elements. What approach would be appropriate to chunk (split)…
• ### 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 repeated…
• ### Merge/flatten an array of arrays

I have a JavaScript array like: [["\$6"], ["\$12"], ["\$25"], ["\$25"], ["\$18"], ["\$22"], ["\$10"]] How would I go about merging the separate inner arrays into one like: ["\$6", "\$12", "\$25", ...]…
• ### Find object by id in an array of JavaScript objects

I've got an array: myArray = [{'id':'73','foo':'bar'},{'id':'45','foo':'bar'}, etc.] I'm unable to change the structure of the array. I'm being passed an id of 45, and I want to get 'bar'…