/    Sign up×
Community /Pin to ProfileBookmark

Can anyone exaplain the "0" next "at" inside of the parenthesis?

[QUOTE]

Can you explain how this (0,at); is used for in javascript? I don’t understand why 0 is in there, and what it is used for?

[/QUOTE]

[code=html]var at =inEmail.indexOf(“@”);
var name = inEmail.substr(0,at);
[/code]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@rootMar 01.2016 — 0 denotes position 0 in the string, the at contains the number of the position of the @ in the email, the returned string will be the front of an email address.
Copy linkTweet thisAlerts:
@Ay__351_eMar 01.2016 — The code I try:
<br/>
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;style type="text/css"&gt;
#indeks td{border:1px solid lime;}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;


&lt;button onclick="myFunction()"&gt;Try it&lt;/button&gt;

&lt;p id="demo"&gt;&lt;/p&gt;
&lt;p id="demo2"&gt;&lt;/p&gt;
&lt;script&gt;
function findTheCharacterAtIndex(){


}
function myFunction() {
var str = "[email protected]";
var t="&lt;table id='indeks'&gt;&lt;tr&gt;";

<i> </i>for(var i=0; i&lt;str.length; i++) {
<i> </i>t+= "&lt;td id='character"+i+"' &gt; "+str.charAt(i)+"&lt;/td&gt;" ;
<i> </i>}
<i> </i>t += "&lt;/tr&gt;";

<i> </i>for(var i=0; i&lt;str.length; i++) {
<i> </i>t+= "&lt;td id='index"+i+"' &gt; "+i+"&lt;/td&gt;" ;
<i> </i>}
<i> </i>t += "&lt;/tr&gt;&lt;/table&gt;";

<i> </i>var ara="@";
<i> </i>var n = str.indexOf(ara);
<i> </i>alert("str.indexOf(ara) : "+str.indexOf(ara));
<i> </i>var el= document.getElementById("demo");
<i> </i>el.innerHTML = t;
<i> </i>var h = document.getElementById('character'+n);
<i> </i>h.style.backgroundColor="pink";
<i> </i>var b = document.getElementById('index'+n);
<i> </i>b.style.backgroundColor="pink";

<i> </i>var el2=document.getElementById("demo2");
<i> </i>el2.innerHTML = "indeks of "+ara +" is "+ n ;

<i> </i>var start=0;
<i> </i>var ad = str.substr(start,n);
<i> </i>alert( "str.substr(start,n) : "+ad);
<i> </i>var c;
<i> </i>for(var k=start; k&lt;n; k++) {
<i> </i>c= document.getElementById("character"+k);
<i> </i>c.style.backgroundColor="yellow";

<i> </i>}
}


//http://www.w3schools.com/jsref/jsref_indexof.asp

//http://www.w3schools.com/jsref/jsref_substr.asp

&lt;/script&gt;


&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@rootMar 01.2016 — Why Ayse? When all you need to do is

To get the console up, press F12 key. var at =inEmail.indexOf("@");
var name = inEmail.substr(0,at);

str = "The @ is found at position ["+at+"] and returns the string : "+name;
console.log("&gt; "+str );
// alert("&gt; "+str);
( remove the // to get the alert to work.)

to demonstrate the function.
×

Success!

Help @web90 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...