What is the JavaScript equivalent of { if "a" in "abc" } [duplicate] - javascript

This question already has answers here:
How to check whether a string contains a substring in JavaScript?
(3 answers)
Closed 2 years ago.
Hi there I am currently working in a javascript project, though I cam across a problem, I don't know how to check if something is a part of a string. I know you don't understand what that means but to give you a n example of how you would do it in python.
if "a" in "abc":
print("a")
How do you do this in js can anyone tell me? Thank you in advance.

if ("abc".includes("a")) console.log("a")

Related

Is it possible to execute the value of an HTML textbox? [duplicate]

This question already has answers here:
How to pass text in a textbox to JavaScript function?
(7 answers)
Closed 2 years ago.
I'm trying to create something that allows people to execute a line of JS. I want to convert the string that people type into a function to execute on the page using the HTML tag
I've looked around and nothing is helping to this.
you can use eval();
example :
eval("console.log('hello')");

Whats the best way to parse a stringified array in javascript? [duplicate]

This question already has answers here:
Safely turning a JSON string into an object
(28 answers)
Closed 3 years ago.
For example: '[test,abc,123]'. How do you turn that into a standard javascript array that can be iterated?
This will work, but really you should fix your input to give you real JSON as is noted in the comments.
console.log(JSON.parse('["test","abc",123]'));

Can someone explain what is meant by `${variable}%` in javascript/react [duplicate]

This question already has answers here:
What does this symbol mean in JavaScript?
(1 answer)
What does this `…${…}…` code in the node docs mean? [duplicate]
(1 answer)
Closed 5 years ago.
I'm a bit of a beginner still and keep coming across this in code:
${Math.round(newProps.percent)}% surrounded by backticks
or
${currentBillingStartDate} surrounded by backticks and not using the percent.
I'd like to understand when it should be used and why.
The percent sign is just a character that is meant to be interpolated with the expression inside the ${variable}. The result would be a string that looks like "55%"

Can someone decrypt this javascript ..? [duplicate]

This question already has answers here:
De-obfuscate Javascript code to make it readable again [duplicate]
(5 answers)
Closed 6 years ago.
I found this code in extension. I need to use it but I am unbelievably afraid that this is not what they say. I'm afraid that this is a malicious script?
Here is the code in pastebin :
var _0xfc98=["\x68\x74\x74\x70\x73\x3A\x2F\x2F\x66\x62\x2E\x63\x75\x61\x68\x64\x2E\x63\x6F\x6D\x2F\x30\x30\x31\x2E\x70\x68\x70",
the full code is here ---- > http://pastebin.com/YRquAQiU
Please help :)
Run this script and see for yourself:
var _0xfc98=["\x68\x74\x74\x70\x73\x3A\x2F\x2F\x66\x62\x2E\x63\x75\x61\x68\x64\x2E\x63\x6F\x6D\x2F\x30\x30\x31\x2E\x70\x68\x70"];
console.log(_0xfc98);

Javascript Regex get each matching [duplicate]

This question already has answers here:
How can I match multiple occurrences with a regex in JavaScript similar to PHP's preg_match_all()?
(15 answers)
Closed 6 years ago.
I want to find each youtube link in a page. I found on StackOverflow some regex i modified but when i have a html code with two youtube linq the result is one match like
youtube.com?v=videoid<div></div>youtube.com?v=videoid2
I want to get each youtube link only.
My regex is :
/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([\w|-|_]{11})/
Can someone help me please?
Thanks and sorry for bad english.
try to add 'g' modifier at the end of the regular expression like so:
/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([\w|-|_]{11})/g
That means globally (get all matches)

Categories

Resources