fetch json object from json array with a key

hamed

I have a json array that contains some json objects. Suppose I have a course object like this:

{"name": "Math", "unit": "3"}

And my json array is look like this:

[{"name": "Math", "unit": "3"}, {"name": "Physics", "unit": "3"}, ...]

Now I need to get an object with it's name. For example I want to get the course with "Math" name. I know It's possible to loop through each array items and check each item name and return an object that its name is equal to "Math", But my array may be too long and this is not good to loop through long array. This is possible to access object in the array by index, for example array[0] will be equal to {"name": "Math", "unit": "3"}. But I want to access array with key, not index. Is there any better solution for doing that? Any help would be greatly appreciated.

Dhiraj

You can use jQuery's .grep().

var newArray = $.grep(obj, function(item){ return item.name == "Math"; });

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Remove object from JSON array

분류에서Dev

Removing json Array from json object

분류에서Dev

Pass new php array key into json

분류에서Dev

Retrieval of title from json from indexed object array ios using swiftyjson

분류에서Dev

Imploding in PHP an array from Json

분류에서Dev

Parsing JSON Object inside Array in Jackson

분류에서Dev

Filter Array Before Push JSON Object to Javascript

분류에서Dev

JSON object expecting an array of objects but gets nothing

분류에서Dev

Convert JSON Array to Object Node js

분류에서Dev

Reduce JSON object containing JSON objects into an array of the form [Path, Value]

분류에서Dev

How to push Json Array Dynamically within Json object

분류에서Dev

How to find JSON array present in JSON object or not android

분류에서Dev

Ajax JSON access array from the array JSON encode server respond

분류에서Dev

I cannot pull data from JSON object- array after ajax post?

분류에서Dev

Returning object oriented json from sparql queries

분류에서Dev

Swift - Unable to create JSON object from NSData

분류에서Dev

Asynchronously remove JSON object from screen

분류에서Dev

Format text from JSON object(server response)

분류에서Dev

How to parse a list of Integers from a JSON object

분류에서Dev

How to get values from Deserialized JSON object?

분류에서Dev

How to find values from another JSON object

분류에서Dev

ExpressJS Fetching value from nested JSON Object

분류에서Dev

Turning my php array into [object Object] json/JavaScript

분류에서Dev

How to get json value from json array using javascript

분류에서Dev

jQuery - How to get JSON array name from nested JSON

분류에서Dev

Console log from within json array

분류에서Dev

Make json from array of objects javascript

분류에서Dev

Move values from JSON to javascript array

분류에서Dev

Laravel - Pass fields from array to JSON

Related 관련 기사

  1. 1

    Remove object from JSON array

  2. 2

    Removing json Array from json object

  3. 3

    Pass new php array key into json

  4. 4

    Retrieval of title from json from indexed object array ios using swiftyjson

  5. 5

    Imploding in PHP an array from Json

  6. 6

    Parsing JSON Object inside Array in Jackson

  7. 7

    Filter Array Before Push JSON Object to Javascript

  8. 8

    JSON object expecting an array of objects but gets nothing

  9. 9

    Convert JSON Array to Object Node js

  10. 10

    Reduce JSON object containing JSON objects into an array of the form [Path, Value]

  11. 11

    How to push Json Array Dynamically within Json object

  12. 12

    How to find JSON array present in JSON object or not android

  13. 13

    Ajax JSON access array from the array JSON encode server respond

  14. 14

    I cannot pull data from JSON object- array after ajax post?

  15. 15

    Returning object oriented json from sparql queries

  16. 16

    Swift - Unable to create JSON object from NSData

  17. 17

    Asynchronously remove JSON object from screen

  18. 18

    Format text from JSON object(server response)

  19. 19

    How to parse a list of Integers from a JSON object

  20. 20

    How to get values from Deserialized JSON object?

  21. 21

    How to find values from another JSON object

  22. 22

    ExpressJS Fetching value from nested JSON Object

  23. 23

    Turning my php array into [object Object] json/JavaScript

  24. 24

    How to get json value from json array using javascript

  25. 25

    jQuery - How to get JSON array name from nested JSON

  26. 26

    Console log from within json array

  27. 27

    Make json from array of objects javascript

  28. 28

    Move values from JSON to javascript array

  29. 29

    Laravel - Pass fields from array to JSON

뜨겁다태그

보관