CN115827109A - Script array element deleting method, device, equipment and storage medium - Google Patents

Script array element deleting method, device, equipment and storage medium Download PDF

Info

Publication number
CN115827109A
CN115827109A CN202310093376.0A CN202310093376A CN115827109A CN 115827109 A CN115827109 A CN 115827109A CN 202310093376 A CN202310093376 A CN 202310093376A CN 115827109 A CN115827109 A CN 115827109A
Authority
CN
China
Prior art keywords
array
deleted
parameter
elements
array element
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310093376.0A
Other languages
Chinese (zh)
Inventor
吴海跃
黄岗
周圣强
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
OP Retail Suzhou Technology Co Ltd
Original Assignee
OP Retail Suzhou Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by OP Retail Suzhou Technology Co Ltd filed Critical OP Retail Suzhou Technology Co Ltd
Priority to CN202310093376.0A priority Critical patent/CN115827109A/en
Publication of CN115827109A publication Critical patent/CN115827109A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Stored Programmes (AREA)

Abstract

The application discloses a method, a device, equipment and a storage medium for deleting a script array element, which relate to the technical field of computers and comprise the following steps: acquiring a first parameter and a second parameter, and judging whether the second parameter represents that a plurality of array elements are deleted or not; the first parameter is used for determining the array elements to be deleted; if so, traversing a preset script array, determining corresponding array elements from the preset script array based on the first parameter to serve as the array elements to be deleted, and deleting the array elements to be deleted until all the array elements in the preset script array are traversed. According to the method and the device, the position of the array element to be deleted does not need to be determined in advance, the array element to be deleted can be determined through the input parameters, the plurality of discontinuous elements can be deleted at one time, the compiling process of developers is simplified, and the execution efficiency of development and codes is improved.

Description

Script array element deleting method, device, equipment and storage medium
Technical Field
The invention relates to the technical field of computers, in particular to a method, a device, equipment and a storage medium for deleting a script array element.
Background
In the prior art, script native provides an array splice (a method for deleting items from an array) method, that is, a method for adding or deleting elements in an array, the deletion of array elements can be set by parameters, a first parameter specifies a position where a new element should be added (accessed), a second parameter defines the number of elements that should be deleted, and the remaining parameters omit that no new element is to be added. However, this method must find the position of the element before calling and only delete the consecutive array elements, and using this method will also change the original array, which may result in incomplete deletion of the array elements.
Disclosure of Invention
In view of the above, the present invention provides a method, an apparatus, a device, and a storage medium for deleting a script array element, which can determine an array element to be deleted through an input parameter and implement deletion of multiple discontinuous elements at one time. The specific scheme is as follows:
in a first aspect, the present application discloses a method for deleting a script array element, including:
acquiring a first parameter and a second parameter, and judging whether the second parameter represents that a plurality of array elements are deleted or not; the first parameter is used for determining the array elements to be deleted;
if so, traversing a preset script array, determining corresponding array elements from the preset script array based on the first parameter to serve as the array elements to be deleted, and deleting the array elements to be deleted until all the array elements in the preset script array are traversed.
Optionally, the traversing a preset script array to determine, based on the first parameter, a corresponding array element from the preset script array as the array element to be deleted includes:
traversing a preset script array based on a reverse order traversal rule and an array element sequence number, and determining a corresponding array element from the preset script array based on the first parameter to serve as the array element to be deleted.
Optionally, after determining whether the second parameter represents that the plurality of array elements are deleted, the method further includes:
and if the second parameter represents that one array element is deleted, traversing a preset script array, determining a first corresponding array element from the preset script array based on the first parameter as the array element to be deleted, deleting the array element to be deleted, and stopping the traversing operation of the preset script array.
Optionally, the traversing a preset script array to determine, based on the first parameter, a first corresponding array element from the preset script array as the array element to be deleted includes:
traversing the preset script array based on a sequence traversal rule and the array element sequence number, and determining a first corresponding array element from the preset script array based on the first parameter as the array element to be deleted.
Optionally, the first parameter is element content of a pre-configured array element to be deleted or a function method for using an array element meeting a preset deletion condition as an array element to be deleted.
Optionally, the process of traversing the target array element in the preset script array includes:
judging the type of the first parameter;
determining whether the target array element traversed currently is an array element to be deleted or not based on the type of the first parameter;
and the target array element is any array element in the preset script array.
Optionally, the determining, based on the type of the first parameter, whether the currently traversed target array element is an array element to be deleted includes:
if the first parameter is a function method for taking the array elements meeting the preset deleting condition as the array elements to be deleted, transmitting the currently traversed target array elements to the function method to determine whether the target array elements meet the preset deleting condition, and if the preset deleting condition is met, determining the target array elements as the array elements to be deleted;
if the first parameter is the element content of the pre-configured array element to be deleted, judging whether the currently traversed target array element is the same as the element content, and if so, determining the target array element as the array element to be deleted.
In a second aspect, the present application discloses a device for deleting a script array element, including:
the parameter acquisition module is used for acquiring a first parameter and a second parameter and judging whether the second parameter represents deletion of a plurality of array elements; the first parameter is used for determining the array elements to be deleted;
and the first element deleting module is used for traversing a preset script array when the second parameter represents that a plurality of array elements are deleted, determining corresponding array elements from the preset script array based on the first parameter to serve as the array elements to be deleted, and deleting the array elements to be deleted until all the array elements in the preset script array are traversed completely.
In a third aspect, the present application discloses an electronic device, comprising:
a memory for storing a computer program;
and the processor is used for executing the computer program to realize the script array element deleting method.
In a fourth aspect, the present application discloses a computer-readable storage medium for storing a computer program, which when executed by a processor implements the foregoing method for deleting a script array element.
Therefore, the method and the device for deleting the array elements obtain a first parameter and a second parameter, and judge whether the second parameter represents that the array elements are deleted or not; the first parameter is used for determining the array elements to be deleted; if so, traversing a preset script array, determining corresponding array elements from the preset script array based on the first parameter to serve as the array elements to be deleted, and deleting the array elements to be deleted until all the array elements in the preset script array are traversed. Therefore, the first parameter for determining the array elements to be deleted and the second parameter for determining whether the array elements to be deleted are deleted or not are input, the preset array is traversed to determine the corresponding array elements to be deleted according to the first parameter, therefore, the positions of the array elements to be deleted are not required to be determined in advance, the array elements to be deleted can be determined through the input parameters, the process of deleting the array elements at one time can be realized no matter whether the deleting elements are continuous or not, the problems that the efficiency is low due to the fact that the array elements need to be cycled for many times and the like are solved, the compiling process of developers is simplified, and the execution efficiency of development and codes is improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.
FIG. 1 is a flow chart of a method for deleting a script array element disclosed in the present application;
FIG. 2 is a flow chart of a method for deleting a plurality of script array elements as disclosed herein;
FIG. 3 is a schematic flow chart of a sequential traversal approach disclosed herein;
FIG. 4 is a flow chart of a single script array element deletion method disclosed herein;
FIG. 5 is a schematic structural diagram of a device for deleting array elements of a script disclosed in the present application;
fig. 6 is a block diagram of an electronic device disclosed in the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
In the prior art, a script native provides an array splice method, that is, a method for adding or deleting elements in an array, the deletion of array elements can be set by parameters, a first parameter specifies a position where a new element should be added (accessed), a second parameter defines the number of elements that should be deleted, and the remaining parameters omit that no new element is to be added. However, this method must find the position of the element before calling and only delete the consecutive array elements, and using the above method will also change the original array, which may result in incomplete deletion of the array elements. In order to solve the above problem, the present application discloses a method for deleting a script array element.
Referring to fig. 1, an embodiment of the present application discloses a method for deleting a script array element, including:
step S11: acquiring a first parameter and a second parameter, and judging whether the second parameter represents that a plurality of array elements are deleted or not; the first parameter is a parameter used for determining the array elements to be deleted.
In this embodiment, first parameters and second parameters input by a developer are obtained, and the type of the first parameter is determined and then recorded by using a variable isFunc, so as to be directly used in subsequent traversal operations. The first parameter is a parameter for determining the array elements to be deleted, and may be element content of the array elements to be deleted configured in advance or a function method for taking the array elements meeting a preset deletion condition as the array elements to be deleted; the second parameter, i.e. multiple, is a parameter for determining whether to delete a plurality of array elements, and a parameter value thereof may be true or false, and then it is determined whether the second parameter represents deletion of a plurality of array elements, if the second parameter is true, it indicates deletion of a plurality of array elements, and if the second parameter is false, it indicates deletion of an array element. Where the array is for storing multiple values in a single variable, and these values may also be accessed by referencing an index number, the stored values are referred to as array elements.
Step S12: if so, traversing a preset script array, determining corresponding array elements from the preset script array based on the first parameter to serve as the array elements to be deleted, and deleting the array elements to be deleted until all the array elements in the preset script array are traversed.
In this embodiment, if the second parameter represents that a plurality of array elements are deleted, that is, the input second parameter value is true, traversal operation is performed on a preset script array, so that a corresponding array element is determined from the preset script array based on the first parameter and is used as the array element to be deleted, and deletion operation is performed on the array element to be deleted until all array elements in the preset script array are completely traversed. Wherein the script includes but is not limited to a scripting language such as JavaScript. Therefore, the developer can determine the array elements to be deleted only by inputting two parameters without determining the positions of the array elements to be deleted in advance, and can realize the process of deleting a plurality of array elements at one time no matter whether the deletion elements are continuous or not, so that the problems of low efficiency and the like caused by the need of repeatedly circulating the array are avoided, the compiling process of the developer is simplified, and the execution efficiency of development and codes is improved.
Therefore, the method and the device for deleting the array elements obtain a first parameter and a second parameter, and judge whether the second parameter represents that the array elements are deleted or not; the first parameter is used for determining the array elements to be deleted; if so, traversing a preset script array, determining corresponding array elements from the preset script array based on the first parameter to serve as the array elements to be deleted, and deleting the array elements to be deleted until all the array elements in the preset script array are traversed. Therefore, the first parameter for determining the array elements to be deleted and the second parameter for determining whether the array elements to be deleted are deleted or not are input, the preset array is traversed to determine the corresponding array elements to be deleted according to the first parameter, therefore, the positions of the array elements to be deleted are not required to be determined in advance, the array elements to be deleted can be determined through the input parameters, the process of deleting the array elements at one time can be realized no matter whether the deleting elements are continuous or not, the problems that the efficiency is low due to the fact that the array elements need to be cycled for many times and the like are solved, the compiling process of developers is simplified, and the execution efficiency of development and codes is improved.
Based on the above embodiments, the present application may determine whether to delete the plurality of array elements and the corresponding array elements to be deleted through the input first parameter and the input second parameter, and then, a process of deleting the plurality of array elements will be described in detail. Referring to fig. 2, an embodiment of the present application discloses a specific method for deleting a script array element, including:
step S21: acquiring a first parameter and a second parameter, judging the type of the first parameter and judging whether the second parameter represents deletion of a plurality of array elements; the first parameter is used for determining the array elements to be deleted.
In this embodiment, a first parameter and a second parameter are first obtained, whether the type of the first parameter is a function method or an element content is determined, if the type of the first parameter is the function method, a variable isFunc is set to true, if the type of the first parameter is the element content, the variable isFunc is set to false, and then whether the second parameter represents deletion of a plurality of array elements is determined.
Step S22: and traversing the preset script array based on the reverse order traversal rule and the serial number of the array elements if the second parameter represents that the array elements are deleted.
In this embodiment, if the second parameter represents that a plurality of array elements need to be deleted, the preset script array is traversed based on the reverse traversal rule and the array element numbers, that is, the preset script array is traversed forward from the last array element of the array, and the array element with the largest array element number is found in the preset script array to determine the element position and start traversal, so that the array element numbers are sequentially decremented until the array element with the array element number of 0 is traversed. Because the conventional array traversal mode is sequential traversal, if only one array element is deleted, the problem of missing the array element to be deleted can be caused by using the sequential traversal mode, but if a plurality of array elements need to be deleted, the problem of missing the array element to be deleted can still exist by using the sequential traversal mode. Referring to fig. 3, if there is an array [ 'a', 'b', 'b', 'c' ], all array elements in the array whose contents are 'b' need to be deleted, and the expected result is [ 'a', 'c' ], if the array is traversed using the sequential traversal method, the traversal process is as follows: during the first traversal, the serial number of the array element is 0, the corresponding array element is 'a', and if the array element is not required to be deleted, the second traversal is performed; in the second traversal, the serial number of the array element is 1, the corresponding array element is 'b', and if the array element needs to be deleted, the array element with the serial number of 1 is deleted, and the third traversal is performed. It should be noted that after the array element with the array element number of 1 is deleted, the array elements with the array element number of 1 all move forward, that is, the array element numbers all decrease by 1, at this time, the current array element number of the array element 'b' with the original array element number of 2 is 1, and the current array element number of the array element 'c' with the original array element number of 3 is 2; since the traversal with the array element number of 1 has been completed, the array element number in the third traversal is 2, and the corresponding array element is 'c', and the array element that does not need to be deleted, the loop is ended and the final result is [ 'a', 'b', 'c' ]. According to the process, the final result obtained by utilizing the sequence traversal mode in the prior art is different from the expected result, the sequence numbers of the array elements can be changed by performing the deletion operation on the array elements in the sequence traversal mode, so that only the first array element 'b' is deleted, namely, the problem that the deletion of the to-be-deleted elements needs to be repeated to delete all the to-be-deleted elements from the array is solved.
In this embodiment, the elements 'a', 'b', 'b', 'c' in the array [ 'a', 'b', 'b', 'c' ] may be numbers, characters, objects, and the like, and when the elements are objects, the definition of the array object may be performed as follows:
var array = [{
"createId":51219,
"createTime":1675000,
"dateProgress":"0/1",
"depId":521,
"depName": a test department 05",
"enterpriseId":104,
"id":1,
"openFinishTime":1675699,
"openTime":1675699,
"prepareTime":167561111,
"projectFinishNum":0,
"projectTotalNum":2,
"state":0,
"taskProgress":"0/2",
"templateId":147,
"templateName": task template 0206",
"totalTime":1,
"useTime":0
},...]。
the array represents the elements of the array [ 'a', 'b', 'b', 'c' ]. If the array element is an object, the operation of this embodiment deletes the element object that meets the condition. If an element with id 1 is deleted, the calling mode is array.
Step S23: if the first parameter is a function method for taking the array elements meeting the preset deletion condition as the array elements to be deleted, transferring the currently traversed target array elements into the function method to determine whether the target array elements meet the preset deletion condition, and if the preset deletion condition is met, determining the target array elements as the array elements to be deleted; the target array element is any array element in the preset script array.
In this embodiment, if the type of the first parameter is a function method for using an array element that meets a preset deletion condition as an array element to be deleted, that is, the variable isFunc is true, the currently traversed target array element is transferred to the function method to determine whether the target array element meets the preset deletion condition, and if the preset deletion condition is not met, the array element corresponding to the next array element serial number is continuously traversed; and if the preset deleting condition is met, determining the target array element as an array element to be deleted. The target array element is any array element in the preset script array; the preset deleting condition can be set by a developer through the function method. For example, if the preset script array is [ '1', '11', '5', '13', '18', '9', ] and the first parameter is a function method that determines array elements with the number of array elements larger than 10 as array elements to be deleted, that is, the preset deletion condition is that the element number is larger than 10, the preset script array is traversed in a reverse traversal manner, each array element is sequentially substituted into the function method for judgment, and '18', '13', and '11' are sequentially determined as array elements to be deleted and a deletion operation is performed, so that the final result is [ '1', '5', '9' ]. Therefore, by setting a function method meeting the preset deletion condition, developers can freely set the screening condition of the elements to be deleted according to the requirements of the developers and determine the array elements to be deleted, thereby preventing the situations of large workload, missing elements and the like caused by setting the element contents of the array elements to be deleted one by one when a large number of array elements exist in the array, and enabling the compilation of the developers to be more diversified and personalized.
Step S24: if the first parameter is the element content of the pre-configured array element to be deleted, judging whether the currently traversed target array element is the same as the element content, and if so, determining the target array element as the array element to be deleted.
In this embodiment, if the type of the first parameter is element content of a pre-configured array element to be deleted, that is, the variable isFunc is false, it is determined whether the content of the currently traversed target array element is the same as the content of the element in the first parameter, and if the content of the currently traversed target array element is the same as the content of the element in the first parameter, the target array element is determined as the array element to be deleted. For example, if the preset script array is [ 'a', 'b', 'b', 'c', ], the first parameter type is element content, and the element content is 'b', the preset script array is traversed, all array elements with the same content as the element content are determined as array elements to be deleted, and a deletion operation is performed, so that the final result is [ 'a', 'c'). Therefore, if only the array element of a certain specific content needs to be deleted, the corresponding function method does not need to be compiled, and the array element to be deleted can be determined by directly inputting the corresponding element content into the first parameter, so that the compiling efficiency is greatly improved, and the workload of developers is reduced.
Step S25: and deleting the array elements to be deleted until all the array elements in the preset script array are traversed.
In this embodiment, after it is determined that the target array element is the to-be-deleted array element, that is, the currently traversed target array element, is deleted, and the array elements corresponding to the next array element sequence number continue to be traversed until all the array elements in the preset script array are traversed. It can be understood that, since a plurality of array elements need to be deleted in this embodiment, but the number of the deleted array elements is not determined, all the array elements in the preset script array need to be traversed to determine all the array elements to be deleted, and the sequence numbers of the array elements are not affected by the reverse traversal, so that the determination of all the array elements can be completed only by performing one traversal on the preset script array. Therefore, the problem of element omission caused by the change of the serial numbers of the array elements due to the sequential traversal mode can be effectively solved, and developers can set the first parameter as a function method or specific element content according to requirements to delete the array elements meeting the conditions, so that the developers can maximally complete the deletion operation of the array elements by using the least compiling workload, and the working efficiency is effectively improved.
Therefore, when a plurality of array elements are deleted, the preset script array can be traversed in a reverse traversal mode, and the problem of element omission caused by the change of the serial numbers of the array elements due to the sequential traversal mode is solved; the developer can also set the first parameter as a function method or specific element content according to the requirement so as to delete the array elements meeting the condition, and the deleted array elements can be discontinuous array elements, so that the developer can maximally complete the deletion operation of the array elements by using the least compiling workload, and the working efficiency is effectively improved.
Based on the above embodiments, it can be seen that in the present application, the deletion of the plurality of array elements is performed by deleting the array elements in a reverse traversal manner, and the parameter to be deleted can be determined according to a function method set by the first parameter or the element content. In addition to deleting a plurality of array elements, the present application may also delete only one array element, and then, a process of deleting only one array element will be described in detail. Referring to fig. 4, an embodiment of the present application discloses a specific method for deleting a script array element, including:
step S31: acquiring a first parameter and a second parameter, judging the type of the first parameter and judging whether the second parameter represents deletion of a plurality of array elements; the first parameter is used for determining the array elements to be deleted.
Step S32: and traversing the preset script array based on the sequence traversal rule and the serial number of the array element if the second parameter represents that one array element is deleted.
In this embodiment, if the second parameter represents that one array element is deleted, that is, the second parameter is false, the preset script array is traversed based on the sequence traversal rule and the sequence number of the array element. It can be understood that if only one array element is deleted, traversal can be finished after the array element to be deleted is deleted, so that no matter how the array element sequence number corresponding to the array element after the array element to be deleted changes, the final result cannot be influenced, and therefore, the preset script array can be traversed in a sequential traversal mode under the condition that only one array element is deleted. Of course, when only one array element is deleted, a reverse-order traversal rule may also be used to perform traversal operation on the preset script array, and a user may select the traversal rule based on requirements.
Step S33: if the first parameter is a function method for taking the array elements meeting the preset deleting condition as the array elements to be deleted, transmitting the currently traversed target array elements to the function method to determine whether the target array elements meet the preset deleting condition, and if the preset deleting condition is met, determining the first target array element as the array element to be deleted.
In this embodiment, if the first parameter is a function method for using an array element that meets a preset deletion condition as an array element to be deleted, the currently traversed target array element is transferred to the function method to determine whether the target array element meets the preset deletion condition, and if the preset deletion condition is not met, the next array element corresponding to the array element serial number is continuously traversed; and if the preset deleting condition is met, determining the first target array element meeting the preset deleting condition as the array element to be deleted. For example, if the preset script array is [ '1', '11', '5', '13', '18', '9', ], the first parameter is a function method for determining an array element with a value of an array element larger than 10 as an array element to be deleted, that is, the preset deletion condition is that the element value is larger than 10, the preset script array is traversed, and each array element is sequentially substituted into the function method for judgment, and the first traversed array element with a value larger than 10 is '11', the '11' is determined as an array element to be deleted, and a deletion operation is performed, so that the traversal operation on the remaining array elements can be stopped, and the final result is [ '1', '5', '13', '18', '9').
Step S34: if the first parameter is the element content of the pre-configured array element to be deleted, judging whether the currently traversed target array element is the same as the element content, and if so, determining the first target array element as the array element to be deleted.
In this embodiment, if the first parameter is the element content of the pre-configured array element to be deleted, it is determined whether the currently traversed target array element is the same as the element content, and if the currently traversed target array element is the same as the element content, the first traversed target array element that is the same as the element content is determined as the array element to be deleted. For example, if the preset script array is [ 'a', 'b', 'b', 'c', ], the first parameter type is element content, and the element content is 'b', the preset script array is traversed, and the first array element which is the same as the element content is determined as the array element to be deleted and a deletion operation is performed, and the final result is [ 'a', 'b', 'c').
Step S35: and deleting the array elements to be deleted, and stopping the traversal operation of the preset script array.
In this embodiment, the determined array element to be deleted is deleted, and at this time, the condition of deleting only one array element is satisfied, so that the operation of traversing other array elements in the preset script array can be stopped, and the problems of resource occupation and the like caused by continuing to perform meaningless traversal operation are avoided.
In this embodiment, the effect of the present application will be compared with that of the prior art from the viewpoint of code implementation. The initial script array is defined as var arr = [ 'a', 'b', 'b', 'c' ]. In the prior art, the code that a developer needs to compile is as follows:
var idx = -1;
// requiring multiple traversals of the array to find the location
while((idx = arr.indexOf('b'))>= 0) {
arr.splice(idx, 1);
}
The method for deleting the script array elements provided by the application is realized by adding a remove removing method in an array prototype extension mode, wherein the prototype extension refers to adding a custom method on an array. The method for deleting array elements in the script is characterized in that the array is used for defining a method which can be called by arrays, the prototypes are called as prototypes, developers only need to call a remove method provided by the application, and few codes are compiled to realize deletion of the array elements by using the method provided by the application, wherein the codes are as follows:
arr.remove('b', true);
the first parameter is 'b', the second parameter is 'true', and the condition that a plurality of array elements need to be deleted and the element content corresponding to the array elements need to be deleted is 'b'. Based on the comparison of the code examples, when the developer deletes the array element by using the scheme, only a few codes need to be compiled, and the developer does not need to traverse for many times to determine the position information of the array element, so that the workload of the developer can be effectively reduced, and the development efficiency can be improved. The specific source code of the scheme is as follows:
Figure SMS_1
for the specific process of the step S31, reference may be made to corresponding contents disclosed in the foregoing embodiments, and details are not repeated here.
Therefore, only one array element can be deleted, the first array element meeting the deletion condition is determined to be deleted through a function method or element content set in the first parameter, the scheme provided by the application is packaged into one method, and developers can compile few codes by calling the method to realize the deletion operation of the array elements. Therefore, the method can realize the operation of deleting only one array element besides deleting a plurality of array elements, so that developers can delete the array elements under most conditions only by using the method provided by the application, the workload of the developers is reduced, and the development efficiency and the code execution efficiency are improved.
Referring to fig. 5, an embodiment of the present application further discloses a device for deleting a script array element, which includes:
the parameter obtaining module 11 is configured to obtain a first parameter and a second parameter, and determine whether the second parameter represents deletion of multiple array elements; the first parameter is used for determining the array elements to be deleted;
the first element deleting module 12 is configured to traverse a preset script array when the second parameter represents that the plurality of array elements are deleted, determine, based on the first parameter, a corresponding array element from the preset script array as the array element to be deleted, and delete the array element to be deleted until all the array elements in the preset script array are traversed.
Therefore, the method and the device for deleting the array elements obtain a first parameter and a second parameter, and judge whether the second parameter represents that the array elements are deleted or not; the first parameter is used for determining the array elements to be deleted; if so, traversing a preset script array, determining corresponding array elements from the preset script array based on the first parameter to serve as the array elements to be deleted, and deleting the array elements to be deleted until all the array elements in the preset script array are traversed. Therefore, the first parameter for determining the array elements to be deleted and the second parameter for determining whether the array elements to be deleted are deleted or not are input, the preset array is traversed to determine the corresponding array elements to be deleted according to the first parameter, therefore, the positions of the array elements to be deleted are not required to be determined in advance, the array elements to be deleted can be determined through the input parameters, the process of deleting the array elements at one time can be realized no matter whether the deleting elements are continuous or not, the problems that the efficiency is low due to the fact that the array elements need to be cycled for many times and the like are solved, the compiling process of developers is simplified, and the execution efficiency of development and codes is improved.
In some specific embodiments, the first element deleting module 12 may be specifically configured to traverse a preset script array based on a reverse traversal rule and an array element sequence number, so as to determine, based on the first parameter, a corresponding array element from the preset script array as the array element to be deleted.
In some specific embodiments, the device for deleting a script array element may further include:
and the second element deleting module is used for traversing a preset script array if the second parameter represents that one array element is deleted, determining a first corresponding array element from the preset script array based on the first parameter as the array element to be deleted, deleting the array element to be deleted, and stopping the traversing operation of the preset script array.
In some specific embodiments, the second element deleting module may be specifically configured to traverse the preset script array based on a sequential traversal rule and an array element sequence number, so as to determine, based on the first parameter, a first corresponding array element from the preset script array as the array element to be deleted.
In some specific embodiments, the first parameter in the parameter obtaining module 11 may specifically be element content of a pre-configured array element to be deleted or a function method for using an array element meeting a preset deletion condition as an array element to be deleted.
In some specific embodiments, the first element deleting module 12 may specifically include:
the type judgment submodule is used for judging the type of the first parameter;
the element determination submodule is used for determining whether the currently traversed target array element is an array element to be deleted or not based on the type of the first parameter; and the target array element is any array element in the preset script array.
In some specific embodiments, the element determination sub-module may specifically include:
a first element determining unit, configured to, when the first parameter is a function method for using an array element that meets a preset deletion condition as an array element to be deleted, transfer the currently traversed target array element into the function method to determine whether the target array element meets the preset deletion condition, and if the preset deletion condition is met, determine the target array element as the array element to be deleted;
and the second element determining unit is used for judging whether the currently traversed target array element is the same as the element content when the first parameter is the element content of the array element to be deleted, and determining the target array element as the array element to be deleted if the target array element is the same as the element content.
Further, an electronic device is disclosed in the embodiments of the present application, and fig. 6 is a block diagram of an electronic device 20 according to an exemplary embodiment, which should not be construed as limiting the scope of the application.
Fig. 6 is a schematic structural diagram of an electronic device 20 according to an embodiment of the present disclosure. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input output interface 25, and a communication bus 26. The memory 22 is used for storing a computer program, and the computer program is loaded and executed by the processor 21 to implement the relevant steps in the script array element deleting method disclosed in any of the foregoing embodiments. In addition, the electronic device 20 in the present embodiment may be specifically an electronic computer.
In this embodiment, the power supply 23 is configured to provide a working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and an external device, and a communication protocol followed by the communication interface is any communication protocol applicable to the technical solution of the present application, and is not specifically limited herein; the input/output interface 25 is configured to acquire external input data or output data to the outside, and a specific interface type thereof may be selected according to specific application requirements, which is not specifically limited herein.
In addition, the storage 22 is used as a carrier for resource storage, and may be a read-only memory, a random access memory, a magnetic disk or an optical disk, etc., and the resources stored thereon may include an operating system 221, a computer program 222, etc., and the storage manner may be a transient storage or a permanent storage.
The operating system 221 is used for managing and controlling each hardware device on the electronic device 20 and the computer program 222, and may be Windows Server, netware, unix, linux, or the like. The computer program 222 may further include a computer program that can be used to perform other specific tasks in addition to the computer program that can be used to perform the script array element deleting method performed by the electronic device 20 disclosed in any of the foregoing embodiments.
Further, the present application also discloses a computer-readable storage medium for storing a computer program; wherein the computer program when executed by a processor implements the script array element deletion method disclosed above. For the specific steps of the method, reference may be made to the corresponding contents disclosed in the foregoing embodiments, which are not described herein again.
The embodiments are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same or similar parts among the embodiments are referred to each other. The device disclosed by the embodiment corresponds to the method disclosed by the embodiment, so that the description is simple, and the relevant points can be referred to the method part for description.
Those of skill would further appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative components and steps have been described above generally in terms of their functionality in order to clearly illustrate this interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. A software module may reside in Random Access Memory (RAM), memory, read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising a … …" does not exclude the presence of another identical element in a process, method, article, or apparatus that comprises the element.
The technical solutions provided by the present application are introduced in detail, and specific examples are applied in the description to explain the principles and embodiments of the present application, and the descriptions of the above examples are only used to help understanding the method and the core ideas of the present application; meanwhile, for a person skilled in the art, according to the idea of the present application, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present application.

Claims (10)

1. A method for deleting a script array element is characterized by comprising the following steps:
acquiring a first parameter and a second parameter, and judging whether the second parameter represents that a plurality of array elements are deleted or not; the first parameter is used for determining the array elements to be deleted;
if so, traversing a preset script array, determining corresponding array elements from the preset script array based on the first parameter to serve as the array elements to be deleted, and deleting the array elements to be deleted until all the array elements in the preset script array are traversed.
2. The method for deleting the script array element according to claim 1, wherein traversing the preset script array to determine the corresponding array element from the preset script array as the array element to be deleted based on the first parameter comprises:
traversing a preset script array based on a reverse order traversal rule and an array element sequence number, and determining a corresponding array element from the preset script array based on the first parameter to serve as the array element to be deleted.
3. The method of claim 1, wherein after determining whether the second parameter characterizes the deletion of the plurality of array elements, further comprising:
and if the second parameter represents that one array element is deleted, traversing a preset script array, determining a first corresponding array element from the preset script array based on the first parameter as the array element to be deleted, deleting the array element to be deleted, and stopping the traversing operation of the preset script array.
4. The method for deleting the script array element according to claim 3, wherein traversing the preset script array to determine a first corresponding array element from the preset script array as the array element to be deleted based on the first parameter comprises:
and traversing the preset script array based on a sequence traversal rule and the array element sequence number, and determining a first corresponding array element from the preset script array based on the first parameter as the array element to be deleted.
5. The method for deleting array elements of scripts according to any one of claims 1 to 4, wherein the first parameter is the element content of the array elements to be deleted, which is configured in advance, or a function method for taking the array elements meeting the preset deletion condition as the array elements to be deleted.
6. The method for deleting the script array element according to claim 5, wherein the step of traversing the target array element in the preset script array comprises:
judging the type of the first parameter;
determining whether the target array element traversed currently is an array element to be deleted or not based on the type of the first parameter;
and the target array element is any array element in the preset script array.
7. The method for deleting the script array element according to claim 6, wherein the determining whether the currently traversed target array element is an array element to be deleted based on the type of the first parameter comprises:
if the first parameter is a function method for taking the array elements meeting the preset deleting condition as the array elements to be deleted, transmitting the currently traversed target array elements to the function method to determine whether the target array elements meet the preset deleting condition, and if the preset deleting condition is met, determining the target array elements as the array elements to be deleted;
if the first parameter is the element content of the pre-configured array element to be deleted, judging whether the currently traversed target array element is the same as the element content, and if so, determining the target array element as the array element to be deleted.
8. A script array element deleting apparatus, comprising:
the parameter acquisition module is used for acquiring a first parameter and a second parameter and judging whether the second parameter represents and deletes a plurality of array elements; the first parameter is used for determining the array elements to be deleted;
and the first element deleting module is used for traversing a preset script array when the second parameter represents that a plurality of array elements are deleted, determining corresponding array elements from the preset script array based on the first parameter to serve as the array elements to be deleted, and deleting the array elements to be deleted until all the array elements in the preset script array are traversed.
9. An electronic device, comprising:
a memory for storing a computer program;
a processor for executing the computer program to implement the script array element deletion method of any one of claims 1 to 7.
10. A computer-readable storage medium for storing a computer program which, when executed by a processor, implements the script array element deleting method of any one of claims 1 to 7.
CN202310093376.0A 2023-02-10 2023-02-10 Script array element deleting method, device, equipment and storage medium Pending CN115827109A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310093376.0A CN115827109A (en) 2023-02-10 2023-02-10 Script array element deleting method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310093376.0A CN115827109A (en) 2023-02-10 2023-02-10 Script array element deleting method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN115827109A true CN115827109A (en) 2023-03-21

Family

ID=85520949

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310093376.0A Pending CN115827109A (en) 2023-02-10 2023-02-10 Script array element deleting method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN115827109A (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1339744A (en) * 1997-02-07 2002-03-13 国际商业机器公司 Computer system for optimizing array update by sequencing array element and method
US6938204B1 (en) * 2000-08-31 2005-08-30 International Business Machines Corporation Array-based extensible document storage format

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1339744A (en) * 1997-02-07 2002-03-13 国际商业机器公司 Computer system for optimizing array update by sequencing array element and method
US6938204B1 (en) * 2000-08-31 2005-08-30 International Business Machines Corporation Array-based extensible document storage format

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
GOODBOYXUAN: "js删除数组内相同元素(同时删除多个元素)", pages 2 - 3, Retrieved from the Internet <URL:http://blog.csdn.net/GoodBoyXuan/article/details/122747359> *

Similar Documents

Publication Publication Date Title
CN110221872B (en) Page jump method and device, electronic equipment and storage medium
CN109739717B (en) Page data acquisition method and device and server
CN111897553B (en) Project system building method, device, equipment and readable storage medium
CN105335132A (en) Method, apparatus and system for user-defined application function
CN113342500B (en) Task execution method, device, equipment and storage medium
CN109947624A (en) Method for monitoring state and device
CN112306471A (en) Task scheduling method and device
CN111694733A (en) API (application programming interface) testing method and device for software development kit SDK (software development kit)
CN116909613A (en) Front-end increment updating method and device and application thereof
CN108023905B (en) Internet of things application system and method
CN113918126A (en) AI modeling flow arrangement method and system based on graph algorithm
CN107885543B (en) Function management method and device of application program and intelligent terminal
CN111294377A (en) Network request sending method of dependency relationship, terminal device and storage medium
CN115827109A (en) Script array element deleting method, device, equipment and storage medium
CN111221525A (en) Script code generation method and device, electronic equipment and storage medium
CN116360887A (en) Program parameter loading method, device, equipment and storage medium
CN112988755B (en) Automatic value selecting method, device and equipment for associated data
CN114449063A (en) Message processing method, device and equipment
CN111367597A (en) Color switching method and device and electronic equipment
CN110597517A (en) Method and device for dynamically analyzing mat file
CN117008915B (en) Code compiling method, device and equipment based on register quantity control
CN111061467B (en) Method for efficiently managing front-end engineering request module
CN116501386B (en) Automatic calculation program solving method based on data pool and related device
CN112799933B (en) Automatic test method and device
CN108958654B (en) Management method and related device of storage system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination