'How do I filter through API information to find a perfect match of a specific search param in React?

I have an API call returning 1 movie name at random... The code has it set up so it returns 1 movie name only.

I then have a second API call that uses that movie name in a second axios request to find streaming services available for this specific movie title.

My issue is, the second API call returns an array of 20 or so choices. For example, if I searched for 'Jaws' it delivers results for Jaws, all the other Jaws movies and any other movie with Jaws in the name.

My question is, how do I filter through this return information, to find a perfect match with the right movie title and just show that info? I hope you can help and sure it is going to be some filtering logic. Thankyou! I am new to React so trying to learn.

const optionsParams = { method: 'GET', url: 'https://mdblist.p.rapidapi.com/', params: [], headers: { 'X-RapidAPI-Host': 'mdblist.p.rapidapi.com', 'X-RapidAPI-Key': '384177d302msh9d8e58dffccp1bfa57jsnf3cea9fef042', }, }; axios .request({ ...optionsParams, params: { s: ${movieData.title}} }) .then(function (response) { console.log(response.data); const traktid = response.data.search.traktid; const traktidOptions = { ...optionsParams, params: { t: ${traktid}` } }; axios.request(traktidOptions).then(function (response) {

        const streamingServices = response.data.streams;
        setStreamingState(streamingServices);
        //console.log(streamingState);
        console.log(response.data.streams)

        let temporaryArray = [];

        for (let i = 0; i < response.data.streams.length; i++){

          temporaryArray.push(response.data.streams[i].name)
          console.log(temporaryArray);

       }
     

       setStreamingState(streamingState => [...streamingState, `${temporaryArray}`])

        if (streamingState) {
          console.log(streamingState)
        } else return false;
      })
    })`


Solution 1:[1]

Array methods are the perfect tool for iterating and organising array data.

In this case the Array.prototype.find() will help you look through your array and return a single item based on your criteria.

For example:

const yourArray = ["jaws", "not this jaws", "definitely not jaws"];

const found = yourArray.find(arrayItem => arrayItem === "jaws");

This is a simple example without objects, so you would just need to set the criteria based on an object property.

Solution 2:[2]

This is because you are using V2 syntax in with V3, you can read the namespace in the options.

Tooltip has been moved to the plugins section

For all changes please read the migration guide

const options = {
  type: 'line',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [{
        label: '# of Votes',
        data: [12, 19, 3, 5, 2, 3],
        borderColor: 'orange'
      },
      {
        label: '# of Points',
        data: [7, 11, 5, 8, 3, 7],
        borderColor: 'pink'
      }
    ]
  },
  options: {
    plugins: {
      tooltip: {
        callbacks: {
          title: () => ('Title')
        }
      }
    }
  }
}

const ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
  <canvas id="chartJSContainer" width="600" height="400"></canvas>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.6.2/chart.js"></script>
</body>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jack
Solution 2 LeeLenalee