2

is there anyway to use

find(), findOneBy(), findBy()

in React JS?

I want to use it for array.

Thank you.

3
  • Have you tried already? Is there something that prevents you from using them? Commented Apr 30, 2018 at 8:31
  • Yes, the result is not what I expected. I suggest to use Linq. npmjs.com/package/linq Commented Apr 30, 2018 at 10:27
  • This doesn't make any sense to me. You ask how to use find(), then you suggest to use a partial reimplementation of .NET's object-relational mapping library. How does it help you to use find()? If the result is not what is expected, you should instead post: (1) your code, (2) expected result, (3) observed result Commented Apr 30, 2018 at 17:39

2 Answers 2

2

You Could definitely use it like this.

class App extends Component {
  render() {
    var array1 = [5, 12, 8, 130, 44];
    var found = array1.find(function (element) {
      return element > 10;
    });

    return (<div>{found}</div>);
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you EmCaye for your answer. The example is really helpful.
1

I suspect that you are asking about to use find(), findOneBy(), findBy() as in getting records from some database?

In that case, you might have a bit of misunderstanding. The purpose of React is to handle your DOM, not doing operations to database (like Eloquent ORM on Laravel, for instance)

What you could do is have your web server handle those operations, while providing a REST API endpoints for your React app to hit.

Other than find(), none of those functions are part of javascript Array.prototype. You can do something like this:

[1,2,3,4,5].find(v => v === 3)

But you can not do the same with findOne and findOneBy.

1 Comment

Thank you Jackyef, your explanation is great. And yes, I am getting records from database using REST API.

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.