How to api response change [closed] - node.js

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I want to transfer the data into an array and my api response is like this
inside api response there is: locationslist :"[\"Location 2\",\"Location 2\"]"
How to get a clean response in react Js?
And I am also try a JSON.parse() it's give me error

This should do it just fine:
const localtionList = "[\"Location 2\",\"Location 2\"]";
console.log(JSON.parse(localtionList))

You are getting error because you are trying to parse JavaScript object using JSON.parse(). To fix the issue you need to pass JSON string to the JSON.parse() method like following:
const something = {
locationslist :"[\"Location 2\",\"Location 2\"]"
};
// This code will give error
console.log(JSON.parse(something));
// This will work fine because locationslist
// holds a JSON string
console.log(JSON.parse(something.locationslist));

Related

how to reformat date type from MongoDB to Angular [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
My question is simple how can I pipe type date ?? meanes if the date in MongoDB looks like this :
2021-01-31T23:00:00.000+00:00
and in my case I want it to take this format 2021-01-31 no more
please how can I do it I'm using MEAN stack (MongoDB, Express js, Angular, Node js)
I want to do it without changing it into a string and get a substring is that possible?
Please help
With Angular, You need to use angular datePipe: https://angular.io/api/common/DatePipe
HTML side:
{{ yourDate | date:'yyyy-MM-dd' }}
If you want to convert it typescript side, you need to provide DatePipe in your appModule :
#NgModule({
....
providers:[DatePipe]
....
})
Then you can use it as service in your component:
constructor(datePipe: DatePipe) {}
...
function() {
const date = this.datePipe.transform(yourDate, 'yyyy-MM-dd')
}

Random meme generator discord.js, glitch.com, node.js [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am new to discord.js coding, I have been trying to make a meme generator, any can help me?
You can use npm packages to generate memes.
for this command idea, I will use "random-discord"
First of all , install random-discord by using npm i random-discord random-discord Docs
and create new random-discord app with :
const { Random } = require('random-discord')
const random = new Random
finally, Add this code to your bot main file :
client.on('message', message => {
if(message.content.toLowerCase() === "meme") {
let meme = await random.getMeme()
message.channel.send(meme)
}
})

How to get a firebase's database keys and values [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm new to firebase, and I'm doing a database for my discord.js bot. I know how to do almost everything, except i don't know how to get all the db data. Let me explain:
My database structure looks like this:
database structure
And i would like that when executing the showconfig command, it shows something like this:
announcementsChannel: "news",
autoRole: "false",
autoRoleName: "none",
// etc...
Is there any way to get every key and its value, and putting it all inside a message?
db.collection("users").get().then((querySnapshot) => {
querySnapshot.forEach((doc) => {
console.log(`${doc.id} => ${doc.data()}`);
});
});
You can read the docs online at this link : https://firebase.google.com/docs/firestore/quickstart

What does underscore wrap function do? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Looking at the example given here (http://underscorejs.org/#wrap), I don't really understand what wrap is doing ... Even more so, when the function is "wrapped" it feels the parameters have to be set (for example, what about doing hello('john')? Are there other examples available that explains what wrap is all about? What would be a typical use case for it?
Thanks!
C
_.wrap() can accept more parameters in callback function other than the function you have. For example to make your hello('John') example work we need some modification on the example code to be
var hello = function(name) { return "hello: " + name; };
hello = _.wrap(hello, function(func,name) {
return "before, " + func(name) + ", after";
});
hello('John');

syntax error unexpected string [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have difficulty to solve this string problem
contentString = '<div id="infoHead">Drag me for new coordinates.</br></div>'+results[1].formatted_address+'<div id="latlng">'+
'Latitude: '+dmsLat+'</br>'+'Longitude: '+dmsLng+'</div>'+'</br>'+'<a href="//www.youtube.com/embed/Mzja4le8htk"'
+ 'style="width=420px; height=315px"'
+ 'onclick=' + '"window.open(this.href,'rockclimbing','left=400,top=250,width=420,height=315,toolbar=1,resizable=0');return false;"'
+ '>Click here for more details</a>'
For example through this code:
'"window.open(this.href,'rockclimbing','left=400,top=250,width=420,height=315,toolbar=1,resizable=0');return false;"'
it's show some error where rockclimbing and start from left until sizeable=0 cannot put single quatotion.
So how to solve this problem?
I can't provide the link since this is my second project. Any kind of help I'm really appreciated.
You need to escape the inner quotes:
'"window.open(this.href,\'rockclimbing\',\'left=400,top=250,width=420,height=315,toolbar=1,resizable=0\');return false;"'
Otherwise the single quote before rockclimbing terminates the string.
I will show you how to find your errors.
I am only including our example up to the first error.
As you move this piece into your environment this error should go away, provided
results[1].formatted_address
can be converted to a string.
Move in more and more of your original code as you fix your errors.
Good Luck!
Code Wrapped in Exception Handler for Error Reporting
try {
contentString = '<div id="infoHead">Drag me for new coordinates.</br></div>'
+results[1].formatted_address;
} catch(exception) {
console.log(exception.stack);
}
Console Log Output for Error Diagnosis
ReferenceError: results is not defined
at <anonymous>:2:84
at Object.InjectedScript._evaluateOn (<anonymous>:580:39)
at Object.InjectedScript._evaluateAndWrap (<anonymous>:539:52)
at Object.InjectedScript.evaluate (<anonymous>:458:21)

Resources