What built in methods?


#1

Hello. Can someone tell me some "methods" so that the program only finds the exact matches of my name.

var text = "Hello my name is Benjamin.";
var myName = "Benjamin";
var hits =[ ];

for ( var i = 0 ; i < text.length; i++) {
if ( text[i] === "B") {
for(var j = i ; j < i + myName.length ; j++)
{hits.push(text[j])}
}
}

if ( hits.length === 0) {
console.log ("Your name wasn't found!");
} else {
console.log(hits);
};

I have also found out for some reason that if I put the name "Bob" behind "Benjamin" then it will also log in this:

//
[ 'B',
'e',
'n',
'j',
'a',
'm',
'i',
'n',
'B',
'o',
'b',
'.',
undefined,
undefined,
undefined,
undefined ]

Can someone tell me why it does this??


#2

> 'hello'.indexOf('l')
2
> (new Object()).nonexistantproperty
undefined

#3

I don't understand this part:

(new Object()).nonexistantproperty
undefined


#4

Undefined properties are.. undefined


#5

Oh...... Thank you very much