从$ .grep()返回的JSON数组中删除对象

时间:2018-01-27 18:38:37

标签: jquery arrays json

我正在搜索json对象数组:

let result = $.grep(jsonObjectArray, matchBothNames);
if (result.length == 1) { // unique match found
   matchFound(result); // do stuff with the result
   jsonObjectArray.remove(result);  // how do I do something like this?
}

如何从正在搜索的数组中删除$ .grep()的结果?

对象不具有我可以使用的唯一唯一键/值。

编辑:

这是一个数组样本:

[
   {
      "First Name":"John",
      "Last Name":"Smith",
      "Block":"A",
      "Mark":"75%",
      "Student #":7724945
   },
   {
      "First Name":"Jane",
      "Last Name":"Doe",
      "Block":"C,D",
      "Mark":"56%",
      "Student #":7715245
   },
   ...
]

Doh,现在我看着它学号是唯一的。

1 个答案:

答案 0 :(得分:1)

使用Array#indexOf()Array#splice()

#include<stdio.h>
#include<string.h>
int main(){
    char str[80]="in this program we will find the longest keyword used so that we can";
    int longest=0;
    char word[25];
    char longestword[25];
    int i=0,j;
    while(str[i]!='\0' && str[i]!=' '){
        j=0;
        while(str[i]!='\0' && str[i]!=' '){
            word[j++] = str[i++];
        }

        word[j] = '\0';
        if (strlen(word) > longest){
            longest = strlen(str);
            strcpy(longestword,longest);
        }
        if(str[i]==' '){
            i++;
        }
        printf("longest word is :\n",longestword);
        printf("length is:\n", longest);
        return 0;
    }
}