我有2个数组如下.我想比较两个数组,只提供'check'中不存在于'data'数组中的元素.
var check= ["044", "451"],
data = ["343", "333", "044", "123", "444", "555"];
Run Code Online (Sandbox Code Playgroud)
使用的功能如下.此函数将导致提供'check'数组中的元素,这些元素存在于'data'数组中
function getMatch(a, b) {
var matches = [];
for ( var i = 0; i < a.length; i++ ) {
for ( var e = 0; e < b.length; e++ ) {
if ( a[i] === b[e] ) matches.push( a[i] );
}
}
return matches;
}
getMatch(check, data); // ["044"] ---> this will be the answer as '044' is only present in 'data'
Run Code Online (Sandbox Code Playgroud)
我想要一个"数据"数组中不存在的元素列表.有人能让我知道如何实现这一目标.
我有一个数组和2个这样的变量
var data = ['12','23', '45'];
var location = 'school'
var details = 'student';
Run Code Online (Sandbox Code Playgroud)
我想将此转换为json,如下所示
{
"School Details":[
{"data":"12", "location":"school", "details":"student"},
{"data":"23", "location":"school", "details":"student"},
{"data":"45", "location":"school", "details":"student"}
]
}
Run Code Online (Sandbox Code Playgroud)
请注意:数据数组的值是动态的,可能会有所不同.但是,变量"location"和"details"将始终保持不变.我需要不断地将此静态值插入json中的动态数组值.
有谁知道我怎么能做到这一点?这有点复杂的情况.