1

I am using Angular 5.

In my component, I check if value is equal to "DATE".

isDateColumn(columnName: string){
    this.configData.some((el) => {
      if (columnName == el.key.columnName){
        console.log("FOUND: " + el.dataType + " For " + columnName);
        return el.dataType === "DATE";
      }
    })
    return false;
  }

In my console, I found something like below:

FOUND: DATE For CLIENT_START_DT

But this function still returns me false.

Why is it so?

1 Answer 1

3

This is happening because your return statement return el.dataType === "DATE"; returns from the array.some function not the isDateColumn function. So in the end return false; executes in all cases.

This works:

isDateColumn(columnName: string){
let found = false;
this.configData.some((el) => {
  if (columnName == el.key.columnName && el.dataType === "DATE"){
    console.log("FOUND: " + el.dataType + " For " + columnName);
    found = true;
  }
})
return found;
}
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.