Remove First Character of Link Anchor Text in JavaScript

AmitDiwan
Updated on 12-Sep-2020 07:36:11

420 Views

Here, we have set “Aabout_us” and “Hhome_page” with incorrectly spellings as anchor text.You can use substring(1) along with innerHTML to remove the first character and display them correctly as “about_us” and “home_page” respectively.Example Live Demo Document Aabout_us Hhome_page    [...document.querySelectorAll('.linkDemo div a')].forEach(obj=>    obj.innerHTML=obj.innerHTML.substring(1)) To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.OutputThis will produce the following output with the correct forms ... Read More

Check If Two Arrays Have the Same Values in JavaScript

AmitDiwan
Updated on 12-Sep-2020 07:30:28

361 Views

Let’s say the following are our arrays −var firstArray=[100, 200, 400]; var secondArray=[400, 100, 200];You can sort both the arrays using the sort() method and use for loop to compare each value as in the below code −Examplevar firstArray=[100, 200, 400]; var secondArray=[400, 100, 200]; function areBothArraysEqual(firstArray, secondArray) {    if (!Array.isArray(firstArray) || ! Array.isArray(secondArray) ||    firstArray.length !== secondArray.length)    return false;    var tempFirstArray = firstArray.concat().sort();    var tempSecondArray = secondArray.concat().sort();    for (var i = 0; i < tempFirstArray.length; i++) {       if (tempFirstArray[i] !== tempSecondArray[i])          return false;    }   ... Read More

Access Nested JSON Property Based on Another Property's Value in JavaScript

AmitDiwan
Updated on 12-Sep-2020 07:29:03

534 Views

To access nested JSON property based on another property’s value, the code is as follows −Examplevar actualJSONData = JSON.parse(studentDetails()), studentMarks = getMarksUsingSubjectName(actualJSONData, "JavaScript"); console.log("The student marks="+studentMarks); function getMarksUsingSubjectName(actualJSONData, givenSubjectName){    for(var tempObj of actualJSONData){       if(tempObj.subjectName = givenSubjectName){          return tempObj.marks;       }    } } function studentDetails(){    return JSON.stringify(       [          { firstName : "John", subjectName: "JavaScript", marks : 97 },          { firstName : "David", subjectName: "Java", marks : 98 }       ]    ); }To run the above ... Read More

Replace Array Value from a Specific Position in JavaScript

AmitDiwan
Updated on 12-Sep-2020 07:26:43

543 Views

To replace value from a specific position, use splice() in JavaScript. Following is the code −Examplevar changePosition = 2 var listOfNames = ['John', 'David', 'Mike', 'Sam','Carol'] console.log("Before replacing="); console.log(listOfNames); var name = 'Adam' var result = listOfNames.splice(changePosition, 1, name) console.log("After replacing="); console.log(listOfNames)To run the above program, you need to use the following command −node fileName.js.OutputHere, my file name is demo14.js. This will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo154.js Before replacing= [ 'John', 'David', 'Mike', 'Sam', 'Carol' ] After replacing= [ 'John', 'David', 'Adam', 'Sam', 'Carol' ]

Add a New Column Address in DB2 Table Tab1

Mandalika
Updated on 11-Sep-2020 14:41:49

1K+ Views

We can add a new column in an existing table as per the business requirements. Similarly, we can also remove a column from the table. This could be done using the ALTER table command as below.ALTER TABLE TAB1 ADD COLUMN ADDRESS VARCHAR(100);The ALTER TABLE reserved words are followed by the name of the table which we want to amend. In this case it is TAB1.To add a new column we will use ADD COLUMN and to remove the column we will use the REMOVE COLUMN parameter. This is followed by the name of the column. If this is an addition ... Read More

Add Constraint on DB2 Table for Ages Between 3 to 16 Years

Mandalika
Updated on 11-Sep-2020 14:29:47

252 Views

Constraints are used to restrict the data inserted at a particular column. Constraints can be used in such a way that a value can only be inserted if it satisfies the condition given in constraints. We can give the below parameter during CREATE TABLE command to add a constraint.CREATE TABLE DBSET1.TAB1    (STUDENT_ID CHAR(10) NOT NULL,    ENROLLMENT_ID CHAR(20) NOT NULL,    NAME VARCHAR(50),    AGE SMALLINT CONSTRAINT NUMBER CHECK    (AGE >=3 AND AGE

Add Unique Index for Column Enrollment ID in Tab1

Mandalika
Updated on 11-Sep-2020 14:21:42

236 Views

An index is a lookup table that optimizes the searching of data. An index defined on any table can increase the query speed. The index can be built up on any column of the table and DB2 will generate a logical structure at backend. This will facilitate the search on the table using indexed columns effectively.An index can be unique and non-unique. To create a new unique index at any table we can use below command.CREATE UNIQUE INDEX ENROTAB1    ON TAB1 (ENROLLMENT_ID) ASC;The CREATE UNIQUE INDEX reserved words are followed by the name of the unique index which we ... Read More

Create DB2 Table Tab1 with 4 Columns: Student ID, Enrollment ID, Name, and Age

Mandalika
Updated on 11-Sep-2020 14:12:28

377 Views

A table is a logical structure of a data in a DB2. A table consists of a column which represents the attribute and rows represents the entity. Below command can be issued in order to create a new DB2 table.CREATE TABLE DBSET1.TAB1    (STUDENT_ID CHAR(10) NOT NULL,    ENROLLMENT_ID CHAR(20) NOT NULL,    NAME VARCHAR(50),    AGE SMALLINT    PRIMARY KEY (STUDENT_ID));The CREATE TABLE reserved words are followed by the name of the table which we have to create in the format . Here DBSET1 is the database and TAB1 is the table.The name of the column has to be ... Read More

Add Volume vol34 and Remove Volume vol29 from Storage Group stg1

Mandalika
Updated on 11-Sep-2020 14:07:28

105 Views

A Volume is a group of physical disks which are used to store the data. A storage group is a collection of volumes. We can add or remove the volumes in a storage group in order to adjust the space. Below command can be issued in order to amend the volume in a storage group.ALTER STG1    ADD VOLUMES(VOL34)    REMOVE VOLUMES(VOL29);The ALTER reserved word has to be followed by the name of the storage group which needs to be altered. Which is STG1 in this case. The ADD VOLUMES parameter has the list of volumes which needs to be ... Read More

Create DB2 Bufferpool with Page Size 4096

Mandalika
Updated on 11-Sep-2020 14:04:29

158 Views

Bufferpool is the unit of the main memory which is used to cache the data in the DB2 table. The data is stored in the cache once the database manager reads the data from the disk to the main memory. The bufferpool can be defined by giving the pagesize.The page is the smallest unit of Input/Output that a DB2 database manager can handle. We can create a DB2 bufferpool using the below command−CREATE BUFFERPOOL BP3 PAGESIZE 4096;The CREATE and BUFFERPOOL reserved words are followed by the bufferpool name which we want to create. Finally we will use PAGESIZE parameter to ... Read More

Advertisements