Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

A class I made for creating OOP styled JSON objects

class JSON_Instance{
    // constructor(name, age){
    //   this.name = name;
    //   this.age = age;
    // }
    
    JSONobj = {
      innerArray:[]
    };
    
    insertJSON(str){
      this.JSONobj = str;
      console.log(this.JSONobj)
    }
  
    addToObj(passedArray){    
      try{
        var tmpObj = Object.fromEntries(passedArray);
        this.JSONobj.innerArray.push(tmpObj);
  
      }
      catch(error){
        console.error("Parameter must be a 2D Array")
      }
    }
    
    removeByIndex(indexToRemove){
      this.JSONobj.innerArray.splice(indexToRemove, 1);
    }
    
    saveToLocalStorage(name){
      localStorage.setItem(name, this.stringMe());
    }
    
    pulled = "";
    getFromLocalStorage(name, insertToJSON){
      if(insertToJSON==true){
        this.pulled = localStorage.getItem(name);
        this.JSONobj = this.pulled;
        this.parseMe();
      }else{
        this.pulled = localStorage.getItem(name);  
      }
      
      return this.pulled;
    }
    
    print(){
      console.log(this.JSONobj);
      return this.JSONobj;
  
    }
  
    stringMe(){
      return JSON.stringify(this.JSONobj);
    }
  
    parseMe(){
      this.JSONobj = JSON.parse(this.JSONobj);
      console.log("Parsed!");
      console.log(this.JSONobj);
    }
  
  }
  
//My GIThub
//https://github.com/pixman92/JSON_Instance
Comment

PREVIOUS NEXT
Code Example
Javascript :: Spread Syntax for function 
Javascript :: intialize vue select using cdn 
Javascript :: show dropdown upwards and downward 
Javascript :: jquery elements to json 
Javascript :: browser app get screen siwe 
Javascript :: how to wait for dom in javascript 
Javascript :: apps script convert a1notation to row column 
Javascript :: filter-vs-map-reactjs-and-jsx 
Javascript :: angular data table push not working 
Javascript :: how to check a user is using wifi or cellular data in php 
Javascript :: convert milliseconds to hours minutes seconds days javascript 
Javascript :: convert jquery hide function to pure javascript code 
Javascript :: knex update and list all record mysql 
Javascript :: useEffect time elapsed 
Javascript :: how to add,delete,update property in javascript object 
Javascript :: alpine js x:bind href link 
Javascript :: javascript bind keyboard key 
Javascript :: rollup js global installation 
Javascript :: mysql timestamp to time/days ago function 
Javascript :: Remove adjacent number 
Javascript :: Masonry js css 
Javascript :: var = " "; 
Javascript :: sqlite get row id after insert nodejs 
Javascript :: this.$moment.tz.guess() not working mozilla 
Javascript :: javascript set default button form 
Javascript :: check if element is displayed jsavascript 
Javascript :: cara install parrot os di virtualbox 
Javascript :: how to plot a line only for current day pinescript 
Javascript :: && in react jsx 
Javascript :: Backbone Render And Initialize 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =