Based on the assumption you are already able to fetch the data (quickSearchResults), a parsing function would look like the following:
function findElementInData(dataPoints, nameOrSymbol) {
return dataPoints.filter(point => point.name == nameOrSymbol || point.symbol === nameOrSymbol)
.map(point => {
return { name: point.name, rank: point.rank }
});
}
var elementsByName = findElementInData(quickSearchResults, 'Bitcoin');
console.log(elementsByName); // [{name: "Bitcoin", rank: 1} ]
var elementsBySymbol = findElementInData(quickSearchResults, 'BTC');
console.log(elementsBySymbol); // [{name: "Bitcoin", rank: 1} ]
This will give you all elements matching either the name or the symbol passed for the given array of data.
Update: It appears you do not have access to the data yet. This is a full example:
function findElementInData(dataPoints, nameOrSymbol) {
return dataPoints.filter(point => point.name === nameOrSymbol || point.symbol === nameOrSymbol)
.map(point => {
return { name: point.name, rank: point.rank }
});
}
function getData(dataUrl) {
return fetch(dataUrl)
.then(res => res.json())
}
window.addEventListener('load', () => {
getData('https://s2.coinmarketcap.com/generated/search/quick_search.json')
.then(dataPoints => {
console.log(dataPoints);
let myResultsBTC = findElementInData(dataPoints, 'BTC');
let myResultsBitcoin = findElementInData(dataPoints, 'Bitcoin');
let myResultsEtherum = findElementInData(dataPoints, 'Ethereum');
let myResultsETH = findElementInData(dataPoints, 'ETH');
console.log(myResultsBTC); // {name: "Bitcoin", rank: 1}
console.log(myResultsBitcoin); // {name: "Bitcoin", rank: 1}
console.log(myResultsEtherum); // {name: "Ethereum", rank: 2}
console.log(myResultsETH); // {name: "Ethereum", rank: 2}
})
.catch(err => {
console.error(err);
});
});