How to store an array of objects in local storage and accessing the object's method after retrieval? [duplicate] The 2019 Stack Overflow Developer Survey Results Are InParse JSON String into a Particular Object Prototype in JavaScriptHow do I restore an object's prototype after retrieving from local storage using typescript?Serializing an ES6 class object as JSONHow do I check if an array includes an object in JavaScript?How do I remove objects from a javascript associative array?How to access the first property of an object in Javascript?Adding value from one list to another depanding on button clickedHow do I store an array in localStorage?simple textbox validation in <rich:modalPanel> using JavaScriptHow to check if an object is an array?indexOf method in an object array?Access / process (nested) objects, arrays or JSONTypeError: Cannot read property 'value' of null | reactjs |

Apparent duplicates between Haynes service instructions and MOT

Why isn't the circumferential light around the M87 black hole's event horizon symmetric?

Can someone be penalized for an "unlawful" act if no penalty is specified?

What does "fetching by region is not available for SAM files" means?

Origin of "cooter" meaning "vagina"

Worn-tile Scrabble

Is three citations per paragraph excessive for undergraduate research paper?

Can we generate random numbers using irrational numbers like π and e?

Why can Shazam fly?

If a Druid sees an animal’s corpse, can they wild shape into that animal?

Have you ever entered Singapore using a different passport or name?

Why do UK politicians seemingly ignore opinion polls on Brexit?

Lightning Grid - Columns and Rows?

Can you compress metal and what would be the consequences?

What could be the right powersource for 15 seconds lifespan disposable giant chainsaw?

How to manage monthly salary

Are there incongruent pythagorean triangles with the same perimeter and same area?

Did Section 31 appear in Star Trek: The Next Generation?

Why isn't airport relocation done gradually?

What does Linus Torvalds mean when he says that Git "never ever" tracks a file?

Time travel alters history but people keep saying nothing's changed

Can a rogue use sneak attack with weapons that have the thrown property even if they are not thrown?

How to save as into a customized destination on macOS?

How technical should a Scrum Master be to effectively remove impediments?



How to store an array of objects in local storage and accessing the object's method after retrieval? [duplicate]



The 2019 Stack Overflow Developer Survey Results Are InParse JSON String into a Particular Object Prototype in JavaScriptHow do I restore an object's prototype after retrieving from local storage using typescript?Serializing an ES6 class object as JSONHow do I check if an array includes an object in JavaScript?How do I remove objects from a javascript associative array?How to access the first property of an object in Javascript?Adding value from one list to another depanding on button clickedHow do I store an array in localStorage?simple textbox validation in <rich:modalPanel> using JavaScriptHow to check if an object is an array?indexOf method in an object array?Access / process (nested) objects, arrays or JSONTypeError: Cannot read property 'value' of null | reactjs |



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1
















This question already has an answer here:



  • How do I restore an object's prototype after retrieving from local storage using typescript?

    1 answer



  • Parse JSON String into a Particular Object Prototype in JavaScript

    12 answers



My object class:



 class Dog 

constructor(name)

var _name;

_name = name;

this.getName = function ()
return _name;





I have a button on click event wire to the following function:



 document.getElementById("btnTest").onclick = function () 

var animals = [];

var name = document.getElementById("name").value;
var bday = document.getElementById("bday").value;
var age = document.getElementById("age").value;
var desc = document.getElementById("description").value;

animals.push(new Dog(name, bday, age, desc));

var serializedAnimals = JSON.stringify(animals);

window.localStorage.setItem("list",serializedAnimals);

var list = JSON.parse(window.localStorage.getItem("list"));

console.log(list.getName());



However when i trigger the function from the button click I get this error console message box:



TypeError: list.getName is not a function



What am I doing wrong?










share|improve this question













marked as duplicate by CertainPerformance javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 22 at 3:41


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • Another helpful duplicate: stackoverflow.com/questions/40201589/…

    – Robby Cornelissen
    Mar 22 at 3:43











  • Use instead localStorage.setItem("list",serializedAnimals); var item = localStorage.getItem('list'); console.log(item)

    – Raymond
    Mar 22 at 3:46


















1
















This question already has an answer here:



  • How do I restore an object's prototype after retrieving from local storage using typescript?

    1 answer



  • Parse JSON String into a Particular Object Prototype in JavaScript

    12 answers



My object class:



 class Dog 

constructor(name)

var _name;

_name = name;

this.getName = function ()
return _name;





I have a button on click event wire to the following function:



 document.getElementById("btnTest").onclick = function () 

var animals = [];

var name = document.getElementById("name").value;
var bday = document.getElementById("bday").value;
var age = document.getElementById("age").value;
var desc = document.getElementById("description").value;

animals.push(new Dog(name, bday, age, desc));

var serializedAnimals = JSON.stringify(animals);

window.localStorage.setItem("list",serializedAnimals);

var list = JSON.parse(window.localStorage.getItem("list"));

console.log(list.getName());



However when i trigger the function from the button click I get this error console message box:



TypeError: list.getName is not a function



What am I doing wrong?










share|improve this question













marked as duplicate by CertainPerformance javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 22 at 3:41


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • Another helpful duplicate: stackoverflow.com/questions/40201589/…

    – Robby Cornelissen
    Mar 22 at 3:43











  • Use instead localStorage.setItem("list",serializedAnimals); var item = localStorage.getItem('list'); console.log(item)

    – Raymond
    Mar 22 at 3:46














1












1








1









This question already has an answer here:



  • How do I restore an object's prototype after retrieving from local storage using typescript?

    1 answer



  • Parse JSON String into a Particular Object Prototype in JavaScript

    12 answers



My object class:



 class Dog 

constructor(name)

var _name;

_name = name;

this.getName = function ()
return _name;





I have a button on click event wire to the following function:



 document.getElementById("btnTest").onclick = function () 

var animals = [];

var name = document.getElementById("name").value;
var bday = document.getElementById("bday").value;
var age = document.getElementById("age").value;
var desc = document.getElementById("description").value;

animals.push(new Dog(name, bday, age, desc));

var serializedAnimals = JSON.stringify(animals);

window.localStorage.setItem("list",serializedAnimals);

var list = JSON.parse(window.localStorage.getItem("list"));

console.log(list.getName());



However when i trigger the function from the button click I get this error console message box:



TypeError: list.getName is not a function



What am I doing wrong?










share|improve this question















This question already has an answer here:



  • How do I restore an object's prototype after retrieving from local storage using typescript?

    1 answer



  • Parse JSON String into a Particular Object Prototype in JavaScript

    12 answers



My object class:



 class Dog 

constructor(name)

var _name;

_name = name;

this.getName = function ()
return _name;





I have a button on click event wire to the following function:



 document.getElementById("btnTest").onclick = function () 

var animals = [];

var name = document.getElementById("name").value;
var bday = document.getElementById("bday").value;
var age = document.getElementById("age").value;
var desc = document.getElementById("description").value;

animals.push(new Dog(name, bday, age, desc));

var serializedAnimals = JSON.stringify(animals);

window.localStorage.setItem("list",serializedAnimals);

var list = JSON.parse(window.localStorage.getItem("list"));

console.log(list.getName());



However when i trigger the function from the button click I get this error console message box:



TypeError: list.getName is not a function



What am I doing wrong?





This question already has an answer here:



  • How do I restore an object's prototype after retrieving from local storage using typescript?

    1 answer



  • Parse JSON String into a Particular Object Prototype in JavaScript

    12 answers







javascript






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 22 at 3:39









John VuongJohn Vuong

112




112




marked as duplicate by CertainPerformance javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 22 at 3:41


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by CertainPerformance javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 22 at 3:41


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Another helpful duplicate: stackoverflow.com/questions/40201589/…

    – Robby Cornelissen
    Mar 22 at 3:43











  • Use instead localStorage.setItem("list",serializedAnimals); var item = localStorage.getItem('list'); console.log(item)

    – Raymond
    Mar 22 at 3:46


















  • Another helpful duplicate: stackoverflow.com/questions/40201589/…

    – Robby Cornelissen
    Mar 22 at 3:43











  • Use instead localStorage.setItem("list",serializedAnimals); var item = localStorage.getItem('list'); console.log(item)

    – Raymond
    Mar 22 at 3:46

















Another helpful duplicate: stackoverflow.com/questions/40201589/…

– Robby Cornelissen
Mar 22 at 3:43





Another helpful duplicate: stackoverflow.com/questions/40201589/…

– Robby Cornelissen
Mar 22 at 3:43













Use instead localStorage.setItem("list",serializedAnimals); var item = localStorage.getItem('list'); console.log(item)

– Raymond
Mar 22 at 3:46






Use instead localStorage.setItem("list",serializedAnimals); var item = localStorage.getItem('list'); console.log(item)

– Raymond
Mar 22 at 3:46













1 Answer
1






active

oldest

votes


















0














Methods do not get serialised by JSON.stringify






class Dog 

constructor(name)

var _name;

_name = name;

this.getName = function ()
return _name;




var animals = [];

animals.push(new Dog('name', 'bday', 'age', 'desc'));

var serializedAnimals = JSON.stringify(animals);

console.log(serializedAnimals);

console.log(JSON.stringify( func: () => ));








share|improve this answer





























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Methods do not get serialised by JSON.stringify






    class Dog 

    constructor(name)

    var _name;

    _name = name;

    this.getName = function ()
    return _name;




    var animals = [];

    animals.push(new Dog('name', 'bday', 'age', 'desc'));

    var serializedAnimals = JSON.stringify(animals);

    console.log(serializedAnimals);

    console.log(JSON.stringify( func: () => ));








    share|improve this answer



























      0














      Methods do not get serialised by JSON.stringify






      class Dog 

      constructor(name)

      var _name;

      _name = name;

      this.getName = function ()
      return _name;




      var animals = [];

      animals.push(new Dog('name', 'bday', 'age', 'desc'));

      var serializedAnimals = JSON.stringify(animals);

      console.log(serializedAnimals);

      console.log(JSON.stringify( func: () => ));








      share|improve this answer

























        0












        0








        0







        Methods do not get serialised by JSON.stringify






        class Dog 

        constructor(name)

        var _name;

        _name = name;

        this.getName = function ()
        return _name;




        var animals = [];

        animals.push(new Dog('name', 'bday', 'age', 'desc'));

        var serializedAnimals = JSON.stringify(animals);

        console.log(serializedAnimals);

        console.log(JSON.stringify( func: () => ));








        share|improve this answer













        Methods do not get serialised by JSON.stringify






        class Dog 

        constructor(name)

        var _name;

        _name = name;

        this.getName = function ()
        return _name;




        var animals = [];

        animals.push(new Dog('name', 'bday', 'age', 'desc'));

        var serializedAnimals = JSON.stringify(animals);

        console.log(serializedAnimals);

        console.log(JSON.stringify( func: () => ));








        class Dog 

        constructor(name)

        var _name;

        _name = name;

        this.getName = function ()
        return _name;




        var animals = [];

        animals.push(new Dog('name', 'bday', 'age', 'desc'));

        var serializedAnimals = JSON.stringify(animals);

        console.log(serializedAnimals);

        console.log(JSON.stringify( func: () => ));





        class Dog 

        constructor(name)

        var _name;

        _name = name;

        this.getName = function ()
        return _name;




        var animals = [];

        animals.push(new Dog('name', 'bday', 'age', 'desc'));

        var serializedAnimals = JSON.stringify(animals);

        console.log(serializedAnimals);

        console.log(JSON.stringify( func: () => ));






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 22 at 3:45









        Adrian BrandAdrian Brand

        4,88821124




        4,88821124















            Popular posts from this blog

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해