Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with JSON and JavaScript. 1.add code to the setContacts method that creates a function named replacer. Code the replacer function so it strips

Need help with JSON and JavaScript.

1.add code to the setContacts method that creates a function named replacer. Code the replacer function so it strips all non-numeric characters from the phone number value. Then, use the replacer function with the stringify method.

"use strict";

var storage = { keyContacts: "contacts_1", getContacts: function() { // get string from local storage var storageString = localStorage.getItem(this.keyContacts) || null; //my code var reviver = function (key, value) { if (key === "") return value; if (key === "p") { switch (value.length) { case "7": return value.subString (0,3) + "-" + subString (3); case "10": return value.subString (0,3) + "-" + subString (3,3) + "-" + subString (6); case "11": return value.subString (0,1) + "-" + subString (1,3) + "-" + subString (4,3) + "-" + subString (7); default: return value; } else { return value; } } }; // convert string to JavaScript object and return, or return empty array if string is null return JSON.parse(storageString) || []; }, setContacts: function(value) { // convert JavaScript object to string var storageString = JSON.stringify(value); //my code var replacer = function (key, value) { } // store string in local storage localStorage.setItem(this.keyContacts, storageString); }, clearContacts: function() { localStorage.setItem(this.keyContacts, ""); } };

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

More Books

Students also viewed these Databases questions

Question

KEY QUESTION Refer to columns 1 and 6 in the table for question

Answered: 1 week ago