#Paths
52 messages · Page 1 of 1 (latest)
prolly the code execution doesn't even reach those lines
nvm
i am dumb
wait no @polar orbit can u explain i tough i figured it out but i didn't
because you returned out of the function
even if i don't it still dosen't work
show the actual full code
i want to acces that itemId variable from rl.on but i can't
because it's in a different scope 😳
either save the result to a variable or perform it within the callback function
but how can i save it to a varible since i can't acces if out of rl.on
literally:
let itemId;
// in callback fn
itemId = line;
// out of callback fn
url = itemId;
woooh
wotks
works
👍
must be because the callback is an async function
so it logs undefined with the async or sync callback fn?
all this code is in a async function
what if it's because that event isn't even triggered 🤔
I soved it
now there is 1 more thing is there any shortcut in node.js to compare 2 arrays?
and see in one of the element matches?
or i need to do it with a for loop
What is the end goal here? Just reading the content of the file?
no i am doing a bot that checks a file full of codes for a given keyword by the user let's say the user enters the input dagger my program needs to find that keyword in list of codes and eventually he will find the code that will look like this WEAPON_DAGGER
Because you used the callback variant of readdir while readdirSync and promise variant of readdir exist too. Same for readFile
but the thing is not every code has the word in position 1 something that can match with the user input
so i can't just do .split('_')[1]
Is it json or yaml or random unformatted file?
unformated file
looks like this
With one word on every line? Not that unformatted then. Just read the whole file as array of lines and use .find(…)
Array.prototype.find()
The find() method returns the first element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, undefined is returned.
but find won't return me a list if i have like WEAPON_DAGGER and WEAPON_DAGGER_2?
Then use filter instead
uhh idk to use that but i can look it up
thanks
Array.prototype.filter()
The filter() method creates a shallow copy of a portion of a given array, filtered down to just the elements from the given array that pass the test implemented by the provided function.
@frank sphinx isn't there smth like .findfirst?
The find() method returns the first element in the provided array
#1108654475306094623 message
unless you mean find index?
no i mean find element matching a string
use that first method Qjuh mentioned
the find method?
because now i get the response {my input} is not a function