0

Question about searching values from array into another array. Example of arrays:

 items = [{"name":"Goran", "category":[0:3, 1:5]}, {"name":"Marko", "category":[0:5, 1:4]}]

 arr1 = ["5", "4", "3"]

Typescript try:

let result = items.filter(item => arr1.find(f => f == items.category))

and the result is none. Can you give me hint how can I do this in one line of code. Basically this is filter from template. I you can image an array of checkbox checking the values from json object. So I want to find values where from arr1 in object items.

4
  • [0:3, 1:5] , it should be [3,5] only Commented Jun 15, 2017 at 17:39
  • Is category supposed to be an array of numbers? And if so, do you want ANY item in arr1 to be in the category array? Or for them to contain the same items? Commented Jun 15, 2017 at 21:28
  • Yea category is only an array. And I want to find all numbers from arr1 in category. Commented Jun 15, 2017 at 22:26
  • Can you give an example of the output you were trying to receive? Commented Jun 16, 2017 at 14:17

1 Answer 1

1

Try to use index of :

let result = items.filter(item => {
    return arr1.indexOf(items.category) > -1        
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.