1

I am trying to filter through an array of objects. what am I doing wrong.

My Pipe

 transform(value: any, args?: any): any {
    if (!args) return value;

    return value.filter(item => this.checkValues(item, args));
  }

  checkValues(item, args) {
    const value = Object.keys(item).map(k => item[k]);

    for (var i in value) {
      return value[i].toString().indexOf(args) > -1;
    }
  }

My data will be like

data= [
{key:value},
{key1:value2}
]

I want to search through the values.

After posting this question I came up with a solution.

My current solution

transform(value: any, args?: any): any {
    if (!args) return value;

    return value.filter(item => this.checkValues(item, args));
  }

  checkValues(item, args) {

    const value = Object.keys(item).map(k => item[k]);

    return JSON.stringify(value).indexOf(args) > -1;

  }

Is this good. or any recommended method?

1 Answer 1

1

Can be acheived by

transform(value: any, args?: any): any {
    if (!args) return value;

    return value.filter(item => this.checkValues(item, args));
  }

  checkValues(item, args) {

    const value = Object.keys(item).map(k => item[k]);

    return String(value).indexOf(args) > -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.