Answers for "why two arrays are not equal in javascript"

2

check if 2 arrays are equal javascript

const a = [1, 2, 3];
const b = [4, 5, 6];
const c = [1, 2, 3];

function arrayEquals(a, b) {
  return Array.isArray(a) &&
    Array.isArray(b) &&
    a.length === b.length &&
    a.every((val, index) => val === b[index]);
}

arrayEquals(a, b); // false
arrayEquals(a, c); // true
Posted by: Guest on February-04-2021
0

how to make a variable equal something in a array javascript

//How to make a variable equal a specific element in javascript.

/*====DESCRIPTION STARTS HERE=======
Assuming you've already created an array and a variable, you simply set the
variable equal to the array, specifying the specific location of the value
it holds. Note though that when specifying the location, subtract one
number from the actual number we percieve. The reason for this is that computers
begin counting at 0.
  =====DESCRIPTION ENDS HERE========*/

//=====EXAMPLE=========
var listOfFirstNames = ["Will", "Kotori", "Grace", "James"]
var FirstName = listOfFirstNames[2] /*firstName now has the value of "Grace"
									since grace is the 2nd (or 3rd) element
									of the array*/
Posted by: Guest on October-21-2020

Code answers related to "why two arrays are not equal in javascript"

Browse Popular Code Answers by Language