1

I want to validate the name if it's already exit or not.

if Exist there should be a pop up to change the name

Here is my list of object before saving.

enter image description here

input change

handleStoryboardTitleChange = (e) => {
this.setState({ storyboardTitle: e.target.value });
};

save function

handleSaveButton = () => { };

How to check if boardTitle is already exit , if exit need popup,later it should not execute flow

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
R9102
  • 687
  • 1
  • 9
  • 32
  • 1
    Possible duplicate of [Find a value in an array of objects in Javascript](https://stackoverflow.com/questions/12462318/find-a-value-in-an-array-of-objects-in-javascript) – Hayden Carlson Jun 04 '18 at 18:04
  • @HaydenCarlson i need help in react as well, is this a duplicate – R9102 Jun 04 '18 at 18:05

1 Answers1

4

I usually use this

var index = boardTitlesList.findIndex((item) => {
    return item.boardTitle === SEARCHED_TITLE
});

if (index === -1) {
    /* NOT FOUND */
} else {
    /* FOUND */
}

Edit m54vl37p08

Here you may found polyfill for findIndex

Sasha Kos
  • 2,480
  • 2
  • 22
  • 37