in my case I’m getting the error: allcardsInfo.map is not a function
export function uploadDeck_click(event) {
const { decode } = require('bs58');
function parseDeckCode(deckCode) {
const code = deckCode;
const decoded = decode(code);
const bytes = Array.from(decoded);
const ids = [];
for (let i = 0; i < bytes.length; i += 2) {
ids.push(bytes[i] + bytes[i + 1] * 256);
}
return [ids]; //'1. Original Decklist: ' + deckCode, '2. Code: ' + code, '3. Decoded: ' + decoded, '4. Bytes: ' + bytes,
}
let deckcards = parseDeckCode($w('#inputDeck').value.slice(8));
//console.log(deckcards)
getCards().then(allcardsInfo => {
console.log(allcardsInfo)
const idCartasDeck = deckcards.toString().split(",");
console.log(idCartasDeck)
let results = [] // This is where we want to save the matching results.
// First, map the second array to its names
let mapped = allcardsInfo.map((items => items.id))
// run a forEach loop on the first array
idCartasDeck.forEach(item => {
let index = mapped.indexOf(item);
if (index > -1) {
/* if we found a matching result, we want to save the item and its value using the index above, we can access the matching item the second array and get its value */
results.push(allcardsInfo[index]);
}
})
// After the loop is done, you can run a small code to show you the results
// This is to let you know how many matching results were found.
console.info(`${results.length} items were found!`);
// This is to show you the results, if any
if (results.length > 0) { console.info("The matching results are ", results) }
})
}
my “getCards” fuction from backend:
import {fetch} from 'wix-fetch';
export async function getCards() {
const settings = {
method: 'GET',
headers: {
Accept: 'application/json'
}
};
try {
const fetchResponse = await fetch('https://gist.githubusercontent.com/CristenPerret/5c97ed87212e5385f0034a7999677708/raw/02c3e18aafacedfbb9721161f8b75a7455048e9e/card.json', settings);
const data = await fetchResponse.json();
return data;
} catch (e) {
return e;
}
}
my code does retrieve and split the decoding as I want. So I need to check the decoded numbers with the ‘id’ in the ‘card.json’ i get from the backend code. but with your code the only problem is the error “.map” is not a function.
could you help me?!
thanks