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.










share|improve this question





















  • 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














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.










share|improve this question





















  • 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












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.










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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
















  • 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












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)





share|improve this answer


















  • 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










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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

























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)





share|improve this answer


















  • 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














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)





share|improve this answer


















  • 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












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)





share|improve this answer














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)






share|improve this answer














share|improve this answer



share|improve this answer








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












  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線