1var colors = ["white","blue"];
2colors.unshift("red"); //add red to beginning of colors
3// colors = ["red","white","blue"]
1var person = {
2 "first_name": "Bob",
3 "last_name": "Dylan"
4};
5person.hasOwnProperty('first_name'); //returns true
6person.hasOwnProperty('age'); //returns false
1const names = ["Bob", "Cassandra"]
2
3names.unshift("Alex")
4
5names === ["Alex", "Bob", "Cassandra"]
1//see https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Array/unshift
2
3const array1 = [1, 2, 3];
4
5console.log(array1.unshift(4, 5));
6// expected output: 5
7
8console.log(array1);
9// expected output: Array [4, 5, 1, 2, 3]
1// Build an array of test data.
2var data = [ "X" ];
3
4// Unshift data onto the array. Unshift() prepends elements to
5// the beginning of the given array. Note that it can take more
6// than one argument. In the output, notice that when unshift()
7// takes multiple arguments, they are prepended in a right-to-left
8// order (mimicing their appearence in the arguments list).
9data.unshift( "A" );
10data.unshift( "B", "C" );
11
12// Output resultant array.
13console.log( data );
1var name = [ "john" ];
2name.unshift( "charlie" );
3name.unshift( "joseph", "Jane" );
4console.log(name);
5
6//Output will be
7[" joseph "," Jane ", " charlie ", " john "]