1

I have array list of items like the below

 let sourceList: SourceList[] = [
  {
    Value: "L7",
    Name: "L7",
    IsVisible: false
  },
  {
    Value: "LO",
    Name: "LO",
    IsVisible: false
  },
  {
    Value: "L3",
    Name: "L3",
    IsVisible: false
  },
  {
    Value: "LS",
    Name: "LS",
    IsVisible: false
  }
]

code tried so far

 if(this.sourceList.indexOf("L7",0) != -1 && this.selectedSources.indexOf("LO",0) != -1 ){

  }

but getting an error at "L7"

I am adding items from this souceList array to another array say array2 one by one .. is there any way to check whether the item from the souceList array is in array2 or not ..

I need to do some process if item "L7" and "LO" is in array 2 but I am not able to figure out how can i search both the items at a time in array 2 .. I am using angular 4 ..

Could any one please help on this, that would be very grateful to me

1
  • What's the code you have so far for doing the search? There's also the find method. Commented Oct 8, 2018 at 22:44

1 Answer 1

1

You can use the some method:

if (this.sourceList.some(x => x.Value === "L7") &&
    this.selectedSources.some(x => x.Value === "L0")) {
  ...
}
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.