Found 10483 Articles for Web Development

Removing the odd occurrence of any number/element from an array in JavaScript

AmitDiwan
Updated on 22-Feb-2021 10:17:09

285 Views

Suppose, we have an array of numbers like this −const arr = [1, 6, 3, 1, 3, 1, 6, 3];We are required to write a JavaScript function that takes in one such array as the first and the only argument. Then the function should look for all such numbers in the array that appear for an odd number of times (excluding only once).For example, In the above array, the numbers 1 and 3 both appear for 3 times (odd), so our function should remove the third occurrence of both these numbers.And the output array should look like −const output = ... Read More

Flattening a JSON object in JavaScript

AmitDiwan
Updated on 22-Feb-2021 10:20:27

14K+ Views

Suppose, we have the following JSON object that may contain nesting upto any level −const obj = {    "one": 1,    "two": {       "three": 3    },    "four": {       "five": 5,       "six": {          "seven": 7       },       "eight": 8    },    "nine": 9 };We are required to write a JavaScript function that takes in one such nested JSON object and returns a new object that contains no nesting and maps the corresponding values to the keys using the dot ... Read More

Finding two numbers that produce equal to the sum of rest in JavaScript

AmitDiwan
Updated on 22-Feb-2021 10:22:40

310 Views

Suppose following is the problem:We have a sequence of numbers starting from 1 and upto any arbitrary number, let's call it num. We have to pick two such numbers from the sequence (let's call them m and n), such that:sum(1 to num) - (m + n) = m * nAnd finally, we should return an array of groups of all such numbers.For example −If the input is −const num = 10;Then the output should be −const output = [    [7, 6] ];because sum(1 to 10) = 55and, 55 - (6 + 7) = 6 * 7 = 42ExampleThe code ... Read More

How to set cookie value with AJAX request in JavaScript?

AmitDiwan
Updated on 22-Feb-2021 09:27:40

4K+ Views

We are required to set cookies with AJAX requests or in such a way that any AJAX request sends those cookies to the server.One thing to note here is that every AJAX request made to any remote server automatically sends all our cookies to that very server without us having to do anything. Therefore, with this thing clear, we just have to set a specific key to our document object using JavaScript and whenever we make a network call, that cookie will automatically be sent to the server which we are making the call to.The code for setting the cookie ... Read More

Why doesn’t Postman get a “No 'Access-ControlAllow-Origin' header is present on the requested resource” error in JavaScript

AmitDiwan
Updated on 22-Feb-2021 09:26:23

741 Views

Problem:When we try to make network request to a remote server whose origin is different to our current url (from which we are making the request), we most likely get a CORS error due to different origin problem in the web, whereas while using a tool like Postman, we can successfully avoid this CORS error.We are required to explain the difference in behaviour of response when requested through web and when requested through an extension like postman.Explanation:When we make a network request to a different domain than our page is on using a web browser, it blocks that request and ... Read More

Preview an image before it is uploaded in JavaScript

Aayush Mohan Sinha
Updated on 04-Aug-2023 10:26:33

11K+ Views

The ability to preview an image before it is uploaded holds significant value in the realm of web development, allowing users to have a glimpse of their selected image and make necessary adjustments prior to submission. Employing JavaScript, a versatile programming language, developers can harness the power of client-side processing to implement this functionality seamlessly. In this article, we will embark on an exploration of how to preview an image before it is uploaded using JavaScript, unveiling a step-by-step approach and leveraging seldom-utilized techniques to accomplish this task. By delving into the intricate details of this process, developers will gain ... Read More

How to take screenshot of a div with JavaScript

AmitDiwan
Updated on 22-Feb-2021 14:01:44

2K+ Views

We are required to capture (convert into image) part(s) of our markup that lays out our website and save that captured image or do something with it. So, we are required to devise a way using which we can achieve this described behaviour.As our problem includes capturing any markup element and not just canvas, it’s a bit complex and especially if we plan to do it from scratch. Therefore, for our ease we will use a third party library, htmltocanvas that does exactly what the name suggests, converting the desired markup to canvas, after which we can simply download the canvas ... Read More

How to read JSON file in JavaScript?

AmitDiwan
Updated on 24-Sep-2024 17:19:28

5K+ Views

There are three effective methods to read JSON files in JavaScript using fetch(), import statements, and require(). Please check this article which includes examples and outputs with the approach explanation. JSON (JavaScript Object Notation) is a lightweight data interchange format that's easy for humans to read and write and easy for machines to parse and generate. In this article, we'll explore three different approaches to reading JSON files in JavaScript: Approaches to Read JSON file Using the fetch() method Using the import statement Using the require ... Read More

Navigating your dashboard in Canva

Zahwah Jameel
Updated on 19-Feb-2021 11:05:35

596 Views

Canva is a free graphic designing tool that allows you to create professional designs without any prior skills.Before you dive in and start designing with Canva, you should know about the dashboard of your Canva account so that you can use the features.This is how your account’s dashboard on Canva will look like.Here a few things you can do through your account’s dashboard.Creating a designYou can go to the design tab through various ways from your dashboard.You can click on the ‘create a design’ option present in the top-right corner.You can scroll down and select the suitable template to start ... Read More

How to design a logo using Canva?

Zahwah Jameel
Updated on 19-Feb-2021 11:01:58

1K+ Views

If you are looking to create a logo that represents the face of your company but you don’t have the skills, you can always use Canva. Canva helps you create professional designs in a few minutes. Besides, Canva is free and open to everyone.To create a logo using Canva, follow these four steps.Click ‘create a design’Go to the homepage of Canva and press the ‘create a design’ button. You will find it on the topmost right corner of your dashboard.From the drop−down list of options, select the logo.You will be automatically redirected to the design tab.Select a suitable templateThis is ... Read More

Advertisements