Question: Write using node.js required- get ALL ID and username from the file for example: have a file name text.json in this file have id: 001
Write using node.js required- get ALL ID and username from the file for example: have a file name \"text.json\" in this file have \"id\": 001 \"username\": \"lyche\" \"test\": I'm funny. \"source\" : Facebook \"id\" : 010 \"username\": \"Kylo\"\" \"test\": I'm happy. \"source\" : instagram \"id\": 1000 \"username\": \"phitli\" \"test\": I'm lucky. \"source\" : skype this file has a lot of text, id, username, date.... we don't know. we don't care, only care that getting the ALL id & username of the file couple of things you need to do. --read the text.json\" var fs = required('fs') fs.readFile('favs.json', function jsonfile (error, data) { if(error) throw error; json = JSON.parse(data) }); --second need to get all the Id & username from the file. -- for this one, don't care how you do it BUT YOU NEED TO CALL THAT ID AND USERNAME LATER OUTSIDE THE FUNCTION. -- what do it mean outside the function is example: We can get all the username and id in the fs.readFile('favs.json', function jsonfile (error, data) { if(error) throw error; json = JSON.parse(data) for(.......){ // we can get all the username and id here and print here (BUT WHAT I MEAN IS I NEED TO CALL THE USERNAME AND ID TO ANOTHER FUNCTION AS WElL) }); var userandid = [ // I WANT THE ID AND USERNAME IN THIS FUNCTION AS WELL. ] P/S: you can create many function Dont CARE. Just Make Sure That You can Save The UserName And ID in (var userandid=[ ]) and a string array or Whatever. Because maybe I need to call that username and id that save later. the OUTPUT should look like this: lyche 001 Kylo 010 phitli 1000 If you can help this one. I really appreciate your help.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
