you need to get function with the index you found;

  var func = functions.indexOf(options.indexOf(this.state.type));// this returns index not the actual func
  functions[func] && functionsfunc

My Approach would be like;

  getBTC = () => {
    // .....
  };

  getETH = () => {
    // .....
  };

  getADA = () => {
    // .....
  };

  getCoin = (type) => {
    switch(type) {
    case "BTC": this.getBTC()
      return
    case "ADA":...
    ...
    ...
    }

  componentDidMount() {
    this.getCoin(this.state.type)
  }
Answer from ilkerkaran on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ react โ€บ react_es6_array_methods.asp
React ES6 Array Methods
There are many JavaScript array methods. One of the most useful in React is the .map() array method. The .map() method allows you to run a function on each item in the array, returning a new array as the result.
๐ŸŒ
Medium
medium.com โ€บ @vipraaditya โ€บ mastering-array-manipulation-in-react-a-comprehensive-guide-5f6e1164c9d1
Mastering Array Manipulation in React: A Comprehensive Guide | by Aditya Narayan Tiwari | Medium
December 17, 2023 - To begin, letโ€™s examine the concept of an array method. An array method refers to a function that can be invoked on an array to execute a specific operation involving that array. Here are a few javascript array methods ...
Discussions

javascript - How to call function from function array (React js) - Stack Overflow
Explore Stack Internal ... Save this question. Show activity on this post. I Created array that contains functions and now I am trying to call a function from that array, I tried this code but it's not working and I have no idea how can I do it becuase I am pretty new at react js. More on stackoverflow.com
๐ŸŒ stackoverflow.com
javascript - Reactjs - How to pass an array to a function? - Stack Overflow
I have a component that creates buttons with information from an array, when the user clicks on the button I want to pass the information from this array to a function, but I'm getting '[Object Obj... More on stackoverflow.com
๐ŸŒ stackoverflow.com
javascript - React : how to pass and array from inside a Function to the return (JSX) - Stack Overflow
I am new to React (and still new to JS too), and i am trying to build my first React project. I am fetching an API , rendering some items, and building a Search Bar that filters out the items rende... More on stackoverflow.com
๐ŸŒ stackoverflow.com
javascript - How to map function returning array in react - Stack Overflow
In example 1. I can map the function by passing it as prop to child component, however, what if i don't want to pass the function as a prop to a child component, how can i map the function in the m... More on stackoverflow.com
๐ŸŒ stackoverflow.com
December 26, 2018
๐ŸŒ
DEV Community
dev.to โ€บ jamesncox โ€บ array-methods-33ii
Array Methods - DEV Community
April 29, 2021 - When working with React, you often render specific data based on specific needs/requirements. Like we saw with filter(), we rendered <p> tags of fruits that met a certain requirement. Similarly, you may want to show only the first matching item from an array. In the Codesandbox, under the ".find()" tab, I copy/paste the input form and functions from Filter.js into Find.js and change the filter() method to find().
๐ŸŒ
React Dev Station
reactdevstation.github.io โ€บ 2020 โ€บ 03 โ€บ 19 โ€บ essential-array-functions.html
Essential Array Functions | React Dev Station
March 19, 2020 - The most common array function in React eco-system, we often use to create JSX for the items in an array.
๐ŸŒ
Medium
raymondosy.medium.com โ€บ 5-must-know-array-methods-in-react-da531a02b0ef
5 must-know array methods in React | by Raymond Akalonu | Medium
December 11, 2019 - Simply put, an array method is a method that can be called on an array to perform an action on or with that array. Here are a few javascript array methods used in react. This array method takes in a function that will be called on each element ...
๐ŸŒ
DEV Community
dev.to โ€บ 04anilr โ€บ array-methods-in-reactjs-36jb
Array methods in react.js - DEV Community
March 19, 2024 - Math.max() and Math.min() functions along with the spread operator (...) to find the maximum and minimum values, respectively. We render the results within JSX, displaying the original array, sum, average, maximum, and minimum values. This component, when rendered, will display the array, sum, average, maximum, and minimum values calculated from the array of numbers. Remember that React components are just JavaScript functions, so you can perform any JavaScript operations within them, including mathematical operations on arrays.
Find elsewhere
๐ŸŒ
JavaScript in Plain English
javascript.plainenglish.io โ€บ react-native-array-methods-d469b7f10447
A Guide to React Native Array Methods | by Selahattindemir | JavaScript in Plain English
December 21, 2021 - Simply put, React array methods are the methods that are available as array prototypes with the new version of JavaScript, by which we can navigate the array elements one by one with the help of a callback function and perform certain checks ยท ...
๐ŸŒ
React
react.dev โ€บ learn โ€บ updating-arrays-in-state
Updating Arrays in State โ€“ React
In React, you will be using slice (no p!) a lot more often because you donโ€™t want to mutate objects or arrays in state. Updating Objects explains what mutation is and why itโ€™s not recommended for state. push() will mutate an array, which you donโ€™t want: ... import { useState } from 'react'; let nextId = 0; export default function List() { const [name, setName] = useState(''); const [artists, setArtists] = useState([]); return ( <> <h1>Inspiring sculptors:</h1> <input value={name} onChange={e => setName(e.target.value)} /> <button onClick={() => { artists.push({ id: nextId++, name: name, }); }}>Add</button> <ul> {artists.map(artist => ( <li key={artist.id}>{artist.name}</li> ))} </ul> </> ); }
๐ŸŒ
Scott Bolinger
scottbolinger.com โ€บ home โ€บ 5 critical javascript methods you need to know for react
5 Critical Javascript Methods You Need To Know For React - Scott Bolinger
June 10, 2021 - You can also get the index and original array in your callback function. const arr = [1,2,3,4]; const newArr = arr.map( (val, index, arr) => val + index ); console.log(newArr) // 1,3,5,7 ยท Map does not change the original array. ... In React, you commonly see it used to display an array of objects.
๐ŸŒ
React
legacy.reactjs.org โ€บ docs โ€บ lists-and-keys.html
Lists and Keys โ€“ React
We can use the same keys when we produce two different arrays: function Blog(props) { const sidebar = ( <ul> {props.posts.map((post) => <li key={post.id}> {post.title} </li> )} </ul> ); const content = props.posts.map((post) => <div key={post.id}> <h3>{post.title}</h3> <p>{post.content}</p> </div> ); return ( <div> {sidebar} <hr /> {content} </div> ); } const posts = [ {id: 1, title: 'Hello World', content: 'Welcome to learning React!'}, {id: 2, title: 'Installation', content: 'You can install React from npm.'} ]; const root = ReactDOM.createRoot(document.getElementById('root')); root.render(<Blog posts={posts} />);
๐ŸŒ
LinkedIn
linkedin.com โ€บ pulse โ€บ important-javascript-array-methods-know-before-learning
Important Javascript Array methods to know before learning React.js
July 4, 2023 - ... The filter() method creates a new array with all elements that pass the test implemented by the provided function. It returns a new array with only the elements that meet the specified condition.
Top answer
1 of 3
1

You just initialise input as a string so just keep input for keeping input value not result data. You can create another state for keeping result OR put result data back on Data variable.

Here I am showing you to keep result data separate.

import React, { useState, useEffect } from "react";
import ListItem from "./ListItem";

const List = () => {
  const [data, setData] = useState();
  const [searchResult, setSearchResult] = useState();
  const [input, setInput] = useState("");

  const onInputChange = (event) => {
    setInput(event.target.value);
    const value = event.target.value.toLowerCase();
    let result = [];
    result = data.filter((item) =>
      item.name.toLowerCase().includes(value.toLowerCase())
    );
    setSearchResult(result);
  };

  useEffect(() => {
    const getData = async () => {
      const response = await fetch(
        "https://rickandmortyapi.com/api/character/"
      );
      const obj = await response.json();
      setData(obj.results);
    };
    getData();
  }, []);

  return (
    <div>
      <input type="text" name={input} onChange={onInputChange}></input>
      {input===""? data &&
        data.map((item) => {
          return <ListItem key={item.id} character={item} />;
        }):
        searchResult &&
        searchResult.map((item) => {
          return <ListItem key={item.id} character={item} />;
        })
        }
    </div>
  );
};
export default List;
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

This is separating your original data and search result different.

2 of 3
1

You need to use a variable to store data after filter:

const [data, setData] = useState([]);  

const onInputChange = (event) => {
  setInput(event.target.value);
};

const result = data.filter((item) =>
  item.name.toLowerCase().includes(input.toLowerCase())
);

return (
  ...
  {result?.map((item) => {
    <ListItem key={item.id} character={item} />;
  })}
  ...
)
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 53925423 โ€บ how-to-map-function-returning-array-in-react
javascript - How to map function returning array in react - Stack Overflow
December 26, 2018 - In example 1. I can map the function by passing it as prop to child component, however, what if i don't want to pass the function as a prop to a child component, how can i map the function in the main component itself as shown in example 2. ... class App extends React.Component { render() { return( <div> <Foo data={data()} /> </div> ) } } class Foo extends React.Component { render() { return ( <div> {this.props.data.map(item => { return ( <div>{item.id} {item.name}</div> ) })} </div> ) } } function data() { return ( [ {id: 1, name: "Jack"}, {id: 2, name: "Mark"}, {id: 3, name: "Mike"}, {id: 4, name: "Russell"} ] ) }
๐ŸŒ
Upmostly
upmostly.com โ€บ home โ€บ tutorials โ€บ react filter: filtering arrays in react (with examples)
React Filter: Filtering Arrays in React (With Examples) - Upmostly
January 14, 2023 - Did you know that you can chain array function in JavaScript, such as filter, map, and reduce? This can save many lines of code, although it may be difficult to understand for those new to coding. Finally, we perform another function after the filter function: the map function. This is how we can output the array elements that match the filter condition to the actual user interface inside of li tags. ... import React from 'react'; const names = ['James', 'John', 'Paul', 'Ringo', 'George']; function App() { return ( <div> {names.filter(name => name.includes('J')).map(filteredName => ( <li> {filteredName} </li> ))} </div> ); } export default App;
๐ŸŒ
Medium
medium.com โ€บ @nicsatiembre โ€บ top-5-most-used-array-methods-in-reactjs-792593b19533
Top 5 Most used Array Methods in ReactJS | by Nicole Satiembre | Medium
March 30, 2024 - This determines which item in the array we are currently dealing with. ... Used to reduce the elements of an array to a single value. It iterates over each element in the array and applies a callback function to accumulate a result.
๐ŸŒ
Reddit
reddit.com โ€บ r/reactjs โ€บ passing array of objects to function adds to array
r/reactjs on Reddit: Passing array of objects to function adds to array
February 3, 2024 - That way, `props = {data: [...]}` and you can call `JSON.stringify(props.data)`. If another property was passed into `SummaryBarChart`, it wouldn't also be called `data`, it should have another name. ... It's been 26 hours... and I still have to rebuild my array after this.