javascript - "'null' is not an object (evaluating 'apiData.original_release_date.split')"; -
i'm making app pulls giantbomb's api display catalog of games depending on query searched. want display picture of game, title, , date added.
basically problem having api displays date game created in illogical way (e.g "1983-12-31 00:00:00") last characters being 00:00:00. (which totally redundant) i'm using .split()
, .join()
remove , replace blank string. while of results populate , see results,
i greeted big error screen giving me error cannot make sort of sense since of objects have dates , being replaced accordingly:
[error] : script error { [error] : backtrace = "#0 () @ :0"; [error] : line = 54; [error] : message = "'null' not object (evaluating 'apidata.original_release_date.split')"; [error] : name = typeerror; ; [error] : }
this randomly halt many other rows populating no apparent reason. have own dates well.
this global object...:
var nameobject = { name : "", original_release_date : "", image : "",
which being populated loop
var posts = json.results; //looping through posts via json///////////////////////// (var = 0; < posts.length; i++) { var apidata = json.results[i]; nameobject.name = apidata.name; nameobject.original_release_date = apidata.original_release_date.split("00:00:00").join(""); nameobject.image = apidata.image; console.log(nameobject.name); console.log(apidata.original_release_date);
i want avoid regexp. ideas appreciated greatly. thanks!
considering value 1983-12-31 00:00:00
@ apidata.original_release_date
.
to split can use :
nameobject.original_release_date = apidata.original_release_date.split(" ")[0];
p.s : better if check first format of data ( means if comes expected ).
Comments
Post a Comment