In Go language if we want to add single record/list of records we can use the append() method. But here is the trick adding the single item is pretty much forward and while adding the list/set of records we might face some issue.
Now we will discuss how to handle both the scenarios
Adding a single item/record to list/array:
package main func main() { var finalItemList []string var singleItem string finalItemList = append(finalItemList, singleItem) }
Adding multiple items/list to another list/array:
To add list of items to another list with help of append() we will receive an error as can not use variable of type of list/array as a data type value in argument to append.
To solve this simply we can just use Spread operator ... (3 dots) notation as shown below.
package main
func main() {
var finalItemList []string
var secondItemList []string
finalItemList = append(finalItemList, secondItemList...)
}
Please comment or write us if you have any queries/requirements.
Please like,follow,bookmark,subscribe this site to receive daily updates.
LinkedIn Group - Srinivas4sfdc (I Love Coding... You?)
FaceBook Page - I Love Coding. You?
Please comment or write us if you have any queries/requirements.
Please like,follow,bookmark,subscribe this site to receive daily updates.
LinkedIn Group - Srinivas4sfdc (I Love Coding... You?)
FaceBook Page - I Love Coding. You?
No comments:
Post a Comment