Skip to content

Latest commit

 

History

History
18 lines (12 loc) · 792 Bytes

how_do_you_compare_scalar_arrays.md

File metadata and controls

18 lines (12 loc) · 792 Bytes

How do you compare scalar arrays?

To compare scalar arrays (arrays with primitive data types) in JavaScript, you need to check if both arrays have the same length and if each element is equal. You can do this using loops or Array.prototype.every().

Example:

const arr1 = [1, 2, 3];
const arr2 = [1, 2, 3];
const areArraysEqual = arr1.length === arr2.length && arr1.every((val, index) => val === arr2[index]);
console.log(areArraysEqual); // true

Tags: intermediate, JavaScript, arrays

URL: https://www.tiktok.com/@jsmentoring/photo/7466925859719449889