ReactJs Get Array Length


We can use Array length method to get the length of array in reactjs. This method is also used to count the number of items in Array. Here in this tutorial, we are going to explain how you can get the length of array ie. count Array items using native JavaScript length method. You can also use our line editor to edit and run the code online.


ReactJs Get Array Length | Count Array Items Method Example

You can use the length method to count the number of items in an array-

Example:

<script>
function MyFunction() {
  var myArray = [2, 3, 4, 5, 1, 6, 8];
  var result = myArray.length;
  return (
    <p>Length of Array(Total Items) = {result}</p>
  );
}

ReactDOM.render(
  <MyFunction />,
  document.getElementById('root')
);
</script>

Try it »

If you run the above example it will return 7 ie. total number of items in array. Output of above example will look something like this-

Vue.js Count Array Items JavaScript

Advertisements

Add Comment

📖 Read More