418,061 questions
12253
votes
51
answers
13.6m
views
How can I remove a specific item from an array in JavaScript?
How do I remove a specific value from an array? Something like:
array.remove(value);
Constraints: I have to use core JavaScript. Frameworks are not allowed.
5809
votes
41
answers
5.5m
views
Loop (for each) over an array in JavaScript
How can I loop through all the entries in an array using JavaScript?
5009
votes
64
answers
3.7m
views
How do I check if an array includes a value in JavaScript?
What is the most concise and efficient way to find out if a JavaScript array contains a value?
This is the only way I know to do it:
function contains(a, obj) {
for (var i = 0; i < a.length; i++...
4351
votes
34
answers
3.7m
views
How can I insert an item into an array at a specific index?
I am looking for a JavaScript array insert method, in the style of:
arr.insert(index, item)
It should preferably be in jQuery, but any JavaScript implementation will do at this point.
4231
votes
61
answers
3.5m
views
Sort array of objects by string property value
I have an array of JavaScript objects:
var objs = [
{ first_nom: 'Laszlo', last_nom: 'Jamf' },
{ first_nom: 'Pig', last_nom: 'Bodine' },
{ first_nom: 'Pirate', last_nom: '...
4136
votes
33
answers
3.8m
views
Checking if a key exists in a JavaScript object?
How do I check if a particular key exists in a JavaScript object or array?
If a key doesn't exist, and I try to access it, will it return false? Or throw an error?
4129
votes
42
answers
1.9m
views
Create ArrayList from array
Element[] array = {new Element(1), new Element(2), new Element(3)};
How do I convert the above variable of type Element[] into a variable of type ArrayList<Element>?
ArrayList<Element> ...
4096
votes
46
answers
5.6m
views
Loop through an array in JavaScript
In Java, you can use a for loop to traverse objects in an array as follows:
String[] myStringArray = {"Hello", "World"};
for (String s : myStringArray) {
// Do something
}
Can ...
3360
votes
51
answers
2.1m
views
How can I check if an object is an array? [duplicate]
I'm trying to write a function that either accepts a list of strings, or a single string. If it's a string, then I want to convert it to an array with just the one item so I can loop over it without ...
3111
votes
26
answers
3.9m
views
Deleting an element from an array in PHP
Is there an easy way to delete an element from an array using PHP, such that foreach ($array) no longer includes that element?
I thought that setting it to null would do it, but apparently it does ...
2924
votes
94
answers
3.7m
views
Get all unique values in a JavaScript array (remove duplicates) [duplicate]
I have an array of numbers that I need to make sure are unique. I found the code snippet below on the Internet, and it works great until the array has a zero in it. I found this other script here on ...
2889
votes
30
answers
5.5m
views
How to append something to an array?
How do I append an object (such as a string or number) to an array in JavaScript?
2760
votes
33
answers
2.9m
views
How do I determine whether an array contains a particular value in Java?
I have a String[] with values like so:
public static final String[] VALUES = new String[] {"AB","BC","CD","AE"};
Given String s, is there a good way of testing whether VALUES contains s?
2578
votes
31
answers
6.0m
views
How do I declare and initialize an array in Java?
How do I declare and initialize an array in Java?