比较两个 javascript 数组并创建两个包含缺失元素和新元素的新数组的最有效方法是什么?数组元素将始终是字符串或数字,并且不能 100% 确定它们会以任何方式排序。
var old_array = ['11', '13', '14', '18', '22', '23', '25'];
var new_array = ['11', '13', '15', '16', '17', '23', '25', '31'];
var missing_elements = [];
var new_elements = [];
/*
* some magic goes here
* which compares
* new_array with old_array
*/
console.log(missing_elements); // would produce ['14', '18', '22']
console.log(new_elements); // would produce ['15', '16', '17', '31']
非常感谢!