Javascript return array from array of objects where property value matchesJavascript: How to filter object array based on attributes?What is the most efficient way to deep clone an object in JavaScript?Create ArrayList from arrayHow do I remove a property from a JavaScript object?How do I check if an array includes an object in JavaScript?Sort array of objects by string property valueLoop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?How do I return the response from an asynchronous call?

What to do with someone that cheated their way through university and a PhD program?

Mistake in years of experience in resume?

Is this a typo in Section 1.8.1 Mathematics for Computer Science?

Island of Knights, Knaves and Spies

As an international instructor, should I openly talk about my accent?

Are there moral objections to a life motivated purely by money? How to sway a person from this lifestyle?

What is the unit of time_lock_delta in LND?

What is this word supposed to be?

How bug prioritization works in agile projects vs non agile

What makes accurate emulation of old systems a difficult task?

An array in a equation with curly braces in both sides

Was Dennis Ritchie being too modest in this quote about C and Pascal?

Drawing a german abacus as in the books of Adam Ries

What is the best way to deal with NPC-NPC combat?

Is Diceware more secure than a long passphrase?

Older movie/show about humans on derelict alien warship which refuels by passing through a star

How much of a wave function must reside inside event horizon for it to be consumed by the black hole?

Multiple fireplaces in an apartment building?

Critique of timeline aesthetic

"Whatever a Russian does, they end up making the Kalashnikov gun"? Are there any similar proverbs in English?

How to not starve gigantic beasts

Should the Product Owner dictate what info the UI needs to display?

Could moose/elk survive in the Amazon forest?

Is Electric Central Heating worth it if using Solar Panels?



Javascript return array from array of objects where property value matches


Javascript: How to filter object array based on attributes?What is the most efficient way to deep clone an object in JavaScript?Create ArrayList from arrayHow do I remove a property from a JavaScript object?How do I check if an array includes an object in JavaScript?Sort array of objects by string property valueLoop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?How do I return the response from an asynchronous call?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















Is there a built in Javascript function or library to do the following:



const data = [
name: 'name1', type: 'type1' ,
name: 'name2', type: 'type2' ,
name: 'name3', type: 'type3' ,
name: 'name4', type: 'type2' ,
];


To search the following and return all objects where type = 'type2'



Something similar to data.findIndex((i) => i.type === 'type2') but returns all matches rather than first index?



Thanks










share|improve this question






















  • Possible duplicate of Javascript: How to filter object array based on attributes?

    – Jibin Joseph
    Mar 22 at 16:53

















0















Is there a built in Javascript function or library to do the following:



const data = [
name: 'name1', type: 'type1' ,
name: 'name2', type: 'type2' ,
name: 'name3', type: 'type3' ,
name: 'name4', type: 'type2' ,
];


To search the following and return all objects where type = 'type2'



Something similar to data.findIndex((i) => i.type === 'type2') but returns all matches rather than first index?



Thanks










share|improve this question






















  • Possible duplicate of Javascript: How to filter object array based on attributes?

    – Jibin Joseph
    Mar 22 at 16:53













0












0








0








Is there a built in Javascript function or library to do the following:



const data = [
name: 'name1', type: 'type1' ,
name: 'name2', type: 'type2' ,
name: 'name3', type: 'type3' ,
name: 'name4', type: 'type2' ,
];


To search the following and return all objects where type = 'type2'



Something similar to data.findIndex((i) => i.type === 'type2') but returns all matches rather than first index?



Thanks










share|improve this question














Is there a built in Javascript function or library to do the following:



const data = [
name: 'name1', type: 'type1' ,
name: 'name2', type: 'type2' ,
name: 'name3', type: 'type3' ,
name: 'name4', type: 'type2' ,
];


To search the following and return all objects where type = 'type2'



Something similar to data.findIndex((i) => i.type === 'type2') but returns all matches rather than first index?



Thanks







javascript arrays






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 22 at 16:49









ArthurArthur

64721026




64721026












  • Possible duplicate of Javascript: How to filter object array based on attributes?

    – Jibin Joseph
    Mar 22 at 16:53

















  • Possible duplicate of Javascript: How to filter object array based on attributes?

    – Jibin Joseph
    Mar 22 at 16:53
















Possible duplicate of Javascript: How to filter object array based on attributes?

– Jibin Joseph
Mar 22 at 16:53





Possible duplicate of Javascript: How to filter object array based on attributes?

– Jibin Joseph
Mar 22 at 16:53












2 Answers
2






active

oldest

votes


















9














You are looking for Array.filter():




The filter() method creates a new array with all elements that pass
the test implemented by the provided function.




Example:






const data = [
name: 'name1', type: 'type1' ,
name: 'name2', type: 'type2' ,
name: 'name3', type: 'type3' ,
name: 'name4', type: 'type2' ,
]

const result = data.filter(o => o.type === 'type2')

console.log(result)








share|improve this answer






























    1














    You can use filter()






    const data = [
    name: 'name1', type: 'type1' ,
    name: 'name2', type: 'type2' ,
    name: 'name3', type: 'type3' ,
    name: 'name4', type: 'type2' ,
    ];
    let res = data.filter((type) => type === "type2");
    console.log(res)








    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55304328%2fjavascript-return-array-from-array-of-objects-where-property-value-matches%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      9














      You are looking for Array.filter():




      The filter() method creates a new array with all elements that pass
      the test implemented by the provided function.




      Example:






      const data = [
      name: 'name1', type: 'type1' ,
      name: 'name2', type: 'type2' ,
      name: 'name3', type: 'type3' ,
      name: 'name4', type: 'type2' ,
      ]

      const result = data.filter(o => o.type === 'type2')

      console.log(result)








      share|improve this answer



























        9














        You are looking for Array.filter():




        The filter() method creates a new array with all elements that pass
        the test implemented by the provided function.




        Example:






        const data = [
        name: 'name1', type: 'type1' ,
        name: 'name2', type: 'type2' ,
        name: 'name3', type: 'type3' ,
        name: 'name4', type: 'type2' ,
        ]

        const result = data.filter(o => o.type === 'type2')

        console.log(result)








        share|improve this answer

























          9












          9








          9







          You are looking for Array.filter():




          The filter() method creates a new array with all elements that pass
          the test implemented by the provided function.




          Example:






          const data = [
          name: 'name1', type: 'type1' ,
          name: 'name2', type: 'type2' ,
          name: 'name3', type: 'type3' ,
          name: 'name4', type: 'type2' ,
          ]

          const result = data.filter(o => o.type === 'type2')

          console.log(result)








          share|improve this answer













          You are looking for Array.filter():




          The filter() method creates a new array with all elements that pass
          the test implemented by the provided function.




          Example:






          const data = [
          name: 'name1', type: 'type1' ,
          name: 'name2', type: 'type2' ,
          name: 'name3', type: 'type3' ,
          name: 'name4', type: 'type2' ,
          ]

          const result = data.filter(o => o.type === 'type2')

          console.log(result)








          const data = [
          name: 'name1', type: 'type1' ,
          name: 'name2', type: 'type2' ,
          name: 'name3', type: 'type3' ,
          name: 'name4', type: 'type2' ,
          ]

          const result = data.filter(o => o.type === 'type2')

          console.log(result)





          const data = [
          name: 'name1', type: 'type1' ,
          name: 'name2', type: 'type2' ,
          name: 'name3', type: 'type3' ,
          name: 'name4', type: 'type2' ,
          ]

          const result = data.filter(o => o.type === 'type2')

          console.log(result)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 22 at 16:50









          Ori DroriOri Drori

          83.4k159099




          83.4k159099























              1














              You can use filter()






              const data = [
              name: 'name1', type: 'type1' ,
              name: 'name2', type: 'type2' ,
              name: 'name3', type: 'type3' ,
              name: 'name4', type: 'type2' ,
              ];
              let res = data.filter((type) => type === "type2");
              console.log(res)








              share|improve this answer



























                1














                You can use filter()






                const data = [
                name: 'name1', type: 'type1' ,
                name: 'name2', type: 'type2' ,
                name: 'name3', type: 'type3' ,
                name: 'name4', type: 'type2' ,
                ];
                let res = data.filter((type) => type === "type2");
                console.log(res)








                share|improve this answer

























                  1












                  1








                  1







                  You can use filter()






                  const data = [
                  name: 'name1', type: 'type1' ,
                  name: 'name2', type: 'type2' ,
                  name: 'name3', type: 'type3' ,
                  name: 'name4', type: 'type2' ,
                  ];
                  let res = data.filter((type) => type === "type2");
                  console.log(res)








                  share|improve this answer













                  You can use filter()






                  const data = [
                  name: 'name1', type: 'type1' ,
                  name: 'name2', type: 'type2' ,
                  name: 'name3', type: 'type3' ,
                  name: 'name4', type: 'type2' ,
                  ];
                  let res = data.filter((type) => type === "type2");
                  console.log(res)








                  const data = [
                  name: 'name1', type: 'type1' ,
                  name: 'name2', type: 'type2' ,
                  name: 'name3', type: 'type3' ,
                  name: 'name4', type: 'type2' ,
                  ];
                  let res = data.filter((type) => type === "type2");
                  console.log(res)





                  const data = [
                  name: 'name1', type: 'type1' ,
                  name: 'name2', type: 'type2' ,
                  name: 'name3', type: 'type3' ,
                  name: 'name4', type: 'type2' ,
                  ];
                  let res = data.filter((type) => type === "type2");
                  console.log(res)






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 22 at 16:50









                  Maheer AliMaheer Ali

                  12.9k1330




                  12.9k1330



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55304328%2fjavascript-return-array-from-array-of-objects-where-property-value-matches%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                      Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript