Monica Mona has Published 112 Answers

Loop through a Dictionary in Javascript

Monica Mona
Published on 27-Jun-2018 14:09:27
Here we'll implement a for each function in our class and accept a callback that we can call on every key-value pair. Let's see how we can implement such a function − ExampleforEach(callback) {    for (let prop in this.container) {       // Call the callback as: callback(key, value) ... Read More

Clearing a Dictionary using Javascript

Monica Mona
Published on 27-Jun-2018 14:04:24
We'll implement a clear() function that simply clears the contents of the container. For example,  Exampleclear() {    this.container = {} }You can test this using − Exampleconst myMap = new MyMap(); myMap.put("key1", "value1"); myMap.put("key2", "value2");   myMap.display(); myMap.clear(); myMap.display();OutputThis will give the output −{ key1: 'value1', key2: 'value2' }You can ... Read More

Search Element in a Dictionary using Javascript

Monica Mona
Published on 27-Jun-2018 13:42:55
We'll implement the get method that searches a given key in the dictionary. Exampleget(key) {    if(this.hasKey(key)) {       return this.container[key];    }    return undefined; }Again, JS objects are very much implemented like dictionaries, hence have most of the functionality we can use directly without any more code ... Read More

Add elements to a Dictionary in Javascript

Monica Mona
Published on 27-Jun-2018 13:32:41
Now we'll create the put method that'll allow us to put key-value pairs on the dictionary. Now using this we'll implement the put method.Note that JS has objects that act quite like dictionaries. We can just set the container's key property to value. Exampleput(key, value) {    this.container[key] = value; }You ... Read More

Creating Dictionary using Javascript

Monica Mona
Published on 27-Jun-2018 13:25:13
Let's create a MyMap class so that it doesn't hide the actual Map class in JS. We'll create a container object that'll keep track of all our values that we add to the map. We'll also create a display function that prints the map for us. Exampleclass MyMap {    constructor() ... Read More

Show dangerous action on a table row with Bootstrap

Monica Mona
Published on 21-Jun-2018 06:46:03
Use the .danger class in Bootstrap to show dangerous action for a table rowExampleLive Demo<!DOCTYPE html> <html>    <head>       <title>Bootstrap Example</title>       <link href = "/bootstrap/css/bootstrap.min.css" rel = "stylesheet">       <script src = "/scripts/jquery.min.js"></script>       <script src = "/bootstrap/js/bootstrap.min.js"></script>    </head> ... Read More

How to print a complete tuple in Python using string formatting?

Monica Mona
Published on 18-Apr-2018 11:40:29
When using the old style of string formatting in python, ie, "" % (), if the thing after the percent is a tuple, python tries to break it down and pass individual items in it to the string. For example, tup = (1, 2, 3) print("this is a tuple %s" ... Read More

Vertical align text in a block element with HTML

Monica Mona
Published on 05-Apr-2018 12:29:10
As per the official specification, declare the <a> as a flex container and you need to use align-items to vertically align text along the cross axis.display: flex; align-items: center;You can also go to −display: -moz-box; -moz-box-align: center;The following is the image showing the usage of Flexbox −Read More

How to set all the outline properties in one declaration with JavaScript?

Monica Mona
Published on 27-Feb-2018 14:07:59
To set outline properties, use the outline property. It allows you to set the color, style, and offset of the outline.ExampleYou can try to run the following code to set all the outline properties in one declaration with JavaScript −Live Demo<!DOCTYPE html> <html>    <head>       <style>   ... Read More

How to set an image as the list-item marker with JavaScript?

Monica Mona
Published on 27-Feb-2018 13:20:18
To set an image as the marker in list-item, use the listStyleImage property in JavaScript.ExampleYou can try to run the following code to set an image as the list-item marker with JavaScript −Live Demo<!DOCTYPE html> <html>    <body>       <ol id="myID">          <li>One</li>     ... Read More
Advertisements