skip to Main Content

I’m trying to use array.find() to get the first JSON string that contains amogus. I’ve tried to read the JSON file using fs then using JSON.parse() to make it readable. However, I can’t seem to get it to do what I want it to do.

JSON file:

{stuff: ["hosds29083", "amogus1208", "amogus1213"]

desired output: amogus1208

Thanks.

3

Answers


  1. const foundString = yourParsedJsonObject.stuff.find(string => string.includes("amogus"))
    
    Login or Signup to reply.
  2. Here is a possible solution:

    const json = JSON.parse(data);
    const first = json.stuff.find(obj => obj.includes("your string"))
    
    Login or Signup to reply.
  3. 
    const json = `{
      "stuff": ["hosds29083", "amogus1208", "amogus1213"]
    }`
    const data = JSON.parse(json)
    const findData = data.stuff.find(s=>s.includes("amogus"))
    console.log(findData)
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search