Thursday, January 23, 2020

Simple JaveScript Tricks with Array and Object

Combining Multiple Objects

Consider you have three different objects:
const obj1 = {'No': 1, 'firstname': 'Rakesh'};
const obj2 = {'lastname': 'Patel'};
const obj3 = {'Sex': 'Male','progLang':['.Net','MVC','SharePoint']};

combine all the above 3 object into another object:

const objCombined = {...obj1, ...obj2, ...obj3};

The '…' is the spread operator. You can read more about this in the MDN Web Docs

Check if an object is an array

const obj = {data: 1};
const arr = [1, 2, 3];

Array.isArray(obj);  // false
Array.isArray(arr);  // true

Rest parameter syntax

A function that accepts any number of arguments. There is a special syntax called the rest parameter syntax to create such a function.

Example 1:

function test(...values) {
    console.log(values);
}
test(1);
test(1, 2);
test(1, 2, 3);
test(1, 2, 3, 4);

output:
[1]
[1, 2]
[1, 2, 3]
[1, 2, 3, 4]

you can even pass object as a arguments

Example 2:

function sum(...values) {
    let sum = 0;
    for (let i = 0; i < values.length; i++) {
        sum += values[i];
    }
  
    return sum;
}

console.log(sum(1));
console.log(sum(1, 2));
console.log(sum(1, 2, 3));
console.log(sum(1, 2, 3, 4));

output:
1
3
6
10


Saturday, January 18, 2020

Fill element on hover

Create a button so that on hover the background color fills the element from left, right or center side of the element.

OUT Put


From center towards left and right

NEXT

From center towards top and bottom

NEXT

From center towards corners

NEXT

From right to left

NEXT

From left to right

NEXT

From bottom to top

NEXT

From top to bottom

NEXT

Friday, January 17, 2020

Shortcode in a WordPress Template

Shortcodes in WordPress are invoke for some kind of function to accomplish certain tasks. But what if you want to use a shortcode from within a template instead of with the content of a Post/Page?
You can invoke it with a special function:

Thursday, December 5, 2019

Get Table Name with Row Count from SQL Database

Select the database you want to filter the information about the row count and run following SQL Statement

SELECT 
    T.NAME AS 'TABLE NAME',
    P.[ROWS] AS 'ROW COUNT'
FROM SYS.TABLES T 
INNER JOIN  SYS.PARTITIONS P ON T.OBJECT_ID=P.OBJECT_ID

This help me to know how many rows are there in table. Hope this will help you too.

Monday, November 18, 2019

Block or Disable Cut, Copy and Paste operation Using jQuery

It is required to block the cut, copy and paste operations on some of the textbox. For example, it will be better if we do not allow users to copy paste the data entered in Email and Confirm Email field in order to make the user to type themselves.

The below jQuery code will help us to do the same using preventDefault() method

Move List Items Up and Down Using jQuery

Sometimes, we require moving/scrolling the list items in the select control up and down to sort manually. This little code snippet will help us to do that using jQuery library.

Thursday, November 14, 2019

Convert JSON data to CSV

JSON Data


Output as CSV