Merging 2 Arrays With Different Value Types
Developing in MEAN stack. Express received and process req array parameters (initially string) and Mongoose returns object array property. I am facing very strange problem. Console
Solution 1:
If it's always going to be an array of primitives, it should be quite easy to just compare each of their values like so:
const arr1 = [ '5acde7adf7d2520e3b205970', '5acde7c0f7d2520e3b205971' ];
const arr2 = ["5acde7adf7d2520e3b205970","5acde7c0f7d2520e3b205971"];
constisSame = (arr1, arr2) => {
if (arr1.length !== arr2.length) returnfalse;
return arr1.every((arr1elm, i) => arr1elm === arr2[i]);
}
console.log(isSame(arr1, arr2));
The fact that one array may have been defined with double quotes and one with single quotes shouldn't affect anything, since they're already deserialized - it's still an array of strings underneath, not a string itself.
Post a Comment for "Merging 2 Arrays With Different Value Types"