Method .includes() is not a function error
up vote
0
down vote
favorite
I am studying through Eloquent Javascript, and I have the following code as one of the exercices.
class Group
constructor()
this.arr =
add(value)
if(!this.has(value))
this.arr = this.arr.push(value)
has(value)
return this.arr.includes(value);
delete(value)
this.arr = this.arr.filter(n => n !== value)
static from(collection)
let rec = new Group;
for (let value of collection)
rec.add(value)
return rec
It seems right and it should be working but I get the error
TypeError: arr.includes is not a function
What is that about? I can't find the answer.
javascript function methods include typeerror
add a comment |
up vote
0
down vote
favorite
I am studying through Eloquent Javascript, and I have the following code as one of the exercices.
class Group
constructor()
this.arr =
add(value)
if(!this.has(value))
this.arr = this.arr.push(value)
has(value)
return this.arr.includes(value);
delete(value)
this.arr = this.arr.filter(n => n !== value)
static from(collection)
let rec = new Group;
for (let value of collection)
rec.add(value)
return rec
It seems right and it should be working but I get the error
TypeError: arr.includes is not a function
What is that about? I can't find the answer.
javascript function methods include typeerror
Try to change your "has" method to an array function
– Steve Nosse
Nov 10 at 18:29
3
Which browser/version of JS are you using? See e.g. developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… for compatibility
– jonrsharpe
Nov 10 at 18:29
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am studying through Eloquent Javascript, and I have the following code as one of the exercices.
class Group
constructor()
this.arr =
add(value)
if(!this.has(value))
this.arr = this.arr.push(value)
has(value)
return this.arr.includes(value);
delete(value)
this.arr = this.arr.filter(n => n !== value)
static from(collection)
let rec = new Group;
for (let value of collection)
rec.add(value)
return rec
It seems right and it should be working but I get the error
TypeError: arr.includes is not a function
What is that about? I can't find the answer.
javascript function methods include typeerror
I am studying through Eloquent Javascript, and I have the following code as one of the exercices.
class Group
constructor()
this.arr =
add(value)
if(!this.has(value))
this.arr = this.arr.push(value)
has(value)
return this.arr.includes(value);
delete(value)
this.arr = this.arr.filter(n => n !== value)
static from(collection)
let rec = new Group;
for (let value of collection)
rec.add(value)
return rec
It seems right and it should be working but I get the error
TypeError: arr.includes is not a function
What is that about? I can't find the answer.
javascript function methods include typeerror
javascript function methods include typeerror
asked Nov 10 at 18:27
Zhast
11
11
Try to change your "has" method to an array function
– Steve Nosse
Nov 10 at 18:29
3
Which browser/version of JS are you using? See e.g. developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… for compatibility
– jonrsharpe
Nov 10 at 18:29
add a comment |
Try to change your "has" method to an array function
– Steve Nosse
Nov 10 at 18:29
3
Which browser/version of JS are you using? See e.g. developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… for compatibility
– jonrsharpe
Nov 10 at 18:29
Try to change your "has" method to an array function
– Steve Nosse
Nov 10 at 18:29
Try to change your "has" method to an array function
– Steve Nosse
Nov 10 at 18:29
3
3
Which browser/version of JS are you using? See e.g. developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… for compatibility
– jonrsharpe
Nov 10 at 18:29
Which browser/version of JS are you using? See e.g. developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… for compatibility
– jonrsharpe
Nov 10 at 18:29
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
From docs,
The push() method adds one or more elements to the end of an array and
returns the new length of the array.
Hence, the problem is with this line. this.arr
is no longer an array after this line.
this.arr = this.arr.push(value)
So, update this to following
this.arr.push(value)
1
Thank you, the arr variable became a number, of course!!
– Zhast
Nov 10 at 18:36
@Zhast - Glad to help you!
– Nikhil Aggarwal
Nov 10 at 18:36
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
From docs,
The push() method adds one or more elements to the end of an array and
returns the new length of the array.
Hence, the problem is with this line. this.arr
is no longer an array after this line.
this.arr = this.arr.push(value)
So, update this to following
this.arr.push(value)
1
Thank you, the arr variable became a number, of course!!
– Zhast
Nov 10 at 18:36
@Zhast - Glad to help you!
– Nikhil Aggarwal
Nov 10 at 18:36
add a comment |
up vote
1
down vote
From docs,
The push() method adds one or more elements to the end of an array and
returns the new length of the array.
Hence, the problem is with this line. this.arr
is no longer an array after this line.
this.arr = this.arr.push(value)
So, update this to following
this.arr.push(value)
1
Thank you, the arr variable became a number, of course!!
– Zhast
Nov 10 at 18:36
@Zhast - Glad to help you!
– Nikhil Aggarwal
Nov 10 at 18:36
add a comment |
up vote
1
down vote
up vote
1
down vote
From docs,
The push() method adds one or more elements to the end of an array and
returns the new length of the array.
Hence, the problem is with this line. this.arr
is no longer an array after this line.
this.arr = this.arr.push(value)
So, update this to following
this.arr.push(value)
From docs,
The push() method adds one or more elements to the end of an array and
returns the new length of the array.
Hence, the problem is with this line. this.arr
is no longer an array after this line.
this.arr = this.arr.push(value)
So, update this to following
this.arr.push(value)
edited Nov 10 at 18:42
answered Nov 10 at 18:29
Nikhil Aggarwal
23.1k32647
23.1k32647
1
Thank you, the arr variable became a number, of course!!
– Zhast
Nov 10 at 18:36
@Zhast - Glad to help you!
– Nikhil Aggarwal
Nov 10 at 18:36
add a comment |
1
Thank you, the arr variable became a number, of course!!
– Zhast
Nov 10 at 18:36
@Zhast - Glad to help you!
– Nikhil Aggarwal
Nov 10 at 18:36
1
1
Thank you, the arr variable became a number, of course!!
– Zhast
Nov 10 at 18:36
Thank you, the arr variable became a number, of course!!
– Zhast
Nov 10 at 18:36
@Zhast - Glad to help you!
– Nikhil Aggarwal
Nov 10 at 18:36
@Zhast - Glad to help you!
– Nikhil Aggarwal
Nov 10 at 18:36
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242108%2fmethod-includes-is-not-a-function-error%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Try to change your "has" method to an array function
– Steve Nosse
Nov 10 at 18:29
3
Which browser/version of JS are you using? See e.g. developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… for compatibility
– jonrsharpe
Nov 10 at 18:29