Get country code by country name javascript? [duplicate] - javascript

This question already has answers here:
How to get country name from country code in javascript
(3 answers)
Closed 2 years ago.
Is there a way to get the country code (Alpha-2) from a country name in JavaScript?

You can use this API https://restcountries.eu/
fetch("https://restcountries.eu/rest/v2/name/kenya").then(resp=>{
return resp.json();
}).then(json=>{
console.log(json[0].alpha2Code);
})

Related

How to delete a element from a nested array in firestore [duplicate]

This question already has answers here:
Firestore Update single item in an array field
(2 answers)
how can i update a specific object property within an array in firebase [duplicate]
(2 answers)
Closed 4 months ago.
I want to delete the 0 element of questions array. I've tried this
const documentRef = db.collection(collection).doc(challengeId)
await documentRef.update({
[`stages.0.surveys.0.questions.0`]: firebase.firestore.FieldValue.delete()
})
But it doesn't work. I would appreciate any help. thank you

MongoDB $sort cant sort by two parameters [duplicate]

This question already has answers here:
Sorting on Multiple fields mongo DB
(4 answers)
JavaScript set object key by variable
(8 answers)
Closed 8 months ago.
I have the following code :
{ "$sort" : {sortParam : sortOption}},
it should work but it interpretates it as Im trying to set a value to sortParam. Is there a way I can escape this ?

Use array instead of array of parameters [duplicate]

This question already has answers here:
Passing an array as a function parameter in JavaScript
(12 answers)
Closed 8 years ago.
I need to use the scissors module to join pdfs...
I have a variable number of files to merge so the code looks like:
var files = [scissors("a.pdf"), scissors("b.pdf")];
scissors.join( *** ).deflate().pdfStream().pipe(fs.createWriteStream(output));
Scissors expect one parameter for each file:
scissors.join(scissors("a.pdf"), scissors("b.pdf"), etc
so how can I do?
You can use Function.prototype.apply:
scissors.join.apply(scissors, files).deflate().pdfStream().pipe(stream);

how can i verified if a path exist or not [duplicate]

This question already has answers here:
PHP: How to check if image file exists?
(22 answers)
Closed 8 years ago.
I would like to test if a path like this file:///c:/folder/texts/int.txt is exist or not if it's exist i open it else echo"file doesn't exist" ,somone have any idea please?
Very short google search shows http://php.net/manual/en/function.file-exists.php
bool file_exists ( string $filename )

Is there a JavaScript alternative to isNaN()? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
JavaScript logic for isNaN()
Hey all I want is to check that the entered value in a textbox is not a number or without using the function isNaN();. Is there any way?
parseFloat(value)!== +value;
But what is wrong with isNaN(value)?

Categories

Resources